package main

import (
    "syscall"
	"unsafe"
	"strings"
    "facecat"
	"time"
	"io/ioutil"
)

var ctpDll,_ = syscall.LoadDLL("iCTP.dll")
var ctpUniqueID = 0
var procSetEncoding,_ = ctpDll.FindProc("setEncoding")
var procAskClose2,_ = ctpDll.FindProc("askClose2")
var procAskCloseToday2,_ = ctpDll.FindProc("askCloseToday2")
var procAskOpen2,_ = ctpDll.FindProc("askOpen2")
var procBidClose2,_ = ctpDll.FindProc("bidClose2")
var procBidCloseToday2,_ = ctpDll.FindProc("bidCloseToday2")
var procBidOpen2,_ = ctpDll.FindProc("bidOpen2")
var procCancelOrder,_ = ctpDll.FindProc("cancelOrder")
var procCreate,_ = ctpDll.FindProc("create")
var procGenerateReqID,_ = ctpDll.FindProc("generateReqID")
var procHasNewDatas,_ = ctpDll.FindProc("hasNewDatas")
var procGetAccountData,_ = ctpDll.FindProc("getAccountData")
var procGetBrokerID,_ = ctpDll.FindProc("getBrokerID")
var procGetCommissionRate,_ = ctpDll.FindProc("getCommissionRate")
var procGetDepthMarketData,_ = ctpDll.FindProc("getDepthMarketData")
var procGetInstrumentsData,_ = ctpDll.FindProc("getInstrumentsData")
var procGetInvestorID,_ = ctpDll.FindProc("getInvestorID")
var procGetMarginRate,_ = ctpDll.FindProc("getMarginRate")
var procGetPositionData,_ = ctpDll.FindProc("getPositionData")
var procGetPositionDetailData,_ = ctpDll.FindProc("getPositionDetailData")
var procGetOrderInfo,_ = ctpDll.FindProc("getOrderInfo")
var procGetOrderInfos,_ = ctpDll.FindProc("getOrderInfos")
var procGetSessionID,_ = ctpDll.FindProc("getSessionID")
var procGetSettlementInfo,_ = ctpDll.FindProc("getSettlementInfo")
var procGetTradeRecord,_ = ctpDll.FindProc("getTradeRecord")
var procGetTradeRecords,_ = ctpDll.FindProc("getTradeRecords")
var procGetTradingDate,_ = ctpDll.FindProc("getTradingDate")
var procGetTradingTime,_ = ctpDll.FindProc("getTradingTime")
var procIsClearanced,_ = ctpDll.FindProc("isClearanced")
var procIsClearanceTime,_ = ctpDll.FindProc("isClearanceTime")
var procIsDataOk,_ = ctpDll.FindProc("isDataOk")
var procIsMdLogined,_ = ctpDll.FindProc("isMdLogined")
var procIsTdLogined,_ = ctpDll.FindProc("isTdLogined")
var procIsTradingTime,_ = ctpDll.FindProc("isTradingTime")
var procIsTradingTimeExact,_ = ctpDll.FindProc("isTradingTimeExact")
var procReqCommissionRate,_ = ctpDll.FindProc("reqCommissionRate")
var procReqQrySettlementInfoConfirm,_ = ctpDll.FindProc("reqQrySettlementInfoConfirm")
var procReqQrySettlementInfo,_ = ctpDll.FindProc("reqQrySettlementInfo")
var procReqMarginRate,_ = ctpDll.FindProc("reqMarginRate")
var procStart,_ = ctpDll.FindProc("start")
var procSubMarketDatas,_ = ctpDll.FindProc("subMarketDatas")
var procUnSubMarketDatas,_ = ctpDll.FindProc("unSubMarketDatas")
var procSetMessageID,_ = ctpDll.FindProc("setMessageID")

//资金账号
type AccountData struct{
	//投资者帐号
	accountID string
	//可用资金
	available float64
	//期货结算准备金
	balance float64
	//经纪公司代码
	brokerID string
	//资金差额
	cashIn float64
	//平仓盈亏
	closeProfit float64
	//手续费
	commission float64
	//信用额度
	credit float64
	//币种代码
	currencyID string
	//当前保证金总额
	currMargin float64
	//投资者交割保证金
	deliveryMargin float64
	//入金金额
	deposit float64
	//动态权益(新增)
	dynamicBalance float64
	//交易所交割保证金
	exchangeDeliveryMargin float64
	//交易所保证金
	exchangeMargin float64
	//浮动盈亏
	floatProfit float64
	//冻结的资金
	frozenCash float64
	//冻结的手续费
	frozenCommission float64
	//冻结的保证金
	frozenMargin float64
	//货币质押余额
	fundMortgageAvailable float64
	//货币质入金额
	fundMortgageIn float64
	//货币质出金额
	fundMortgageOut float64
	//利息收入
	interest float64
	//利息基数
	interestBase float64
	//质押金额
	mortgage float64
	//可质押货币金额
	mortgageableFund float64
	//持仓盈亏
	positionProfit float64
	//上次结算准备金
	preBalance float64
	//上次信用额度
	preCredit float64
	//上次存款额
	preDeposit float64
	//上次货币质入金额
	preFundMortgageIn float64
	//上次货币质出金额
	preFundMortgageOut float64
	//上次占用的保证金
	preMargin float64
	//上次质押金额
	preMortgage float64
	//基本准备金
	reserve float64
	//保底期货结算准备金
	reserveBalance float64
	//风险度(新增)
	risk float64
	//结算编号
	settlementID float64
	//特殊产品平仓盈亏
	specProductCloseProfit float64
	//特殊产品手续费
	specProductCommission float64
	//特殊产品交易所保证金
	specProductExchangeMargin float64
	//特殊产品冻结手续费
	specProductFrozenCommission float64
	//特殊产品冻结保证金
	specProductFrozenMargin float64
	//特殊产品占用保证金
	specProductMargin float64
	//特殊产品持仓盈亏
	specProductPositionProfit float64
	//根据持仓盈亏算法计算的特殊产品持仓盈亏
	specProductPositionProfitByAlg float64
	//交易日
	tradingDay string
	//出金金额
	withdraw float64
	//可取资金
	withdrawQuota float64
}

//码表
type Security struct{
	//组合类型
	combinationType string
	//创建日
	createDate string
	//交割月
	deliveryMonth float64
	//交割年份
	deliveryYear float64
	//结束交割日
	endDelivDate string
	//交易所代码
	exchangeID string
	//合约在交易所的代码
	exchangeInstID string
	//到期日
	expireDate string
	//保留小数位数
	digit int
	//合约生命周期状态
	instLifePhase string
	//合约代码
	instrumentID string
	//合约名称
	instrumentName string
	//当前是否交易
	isTrading string
	//多头保证金率
	longMarginRatio float64
	//限价单最大下单量
	maxLimitOrderVolume float64
	//是否使用大额单边保证金算法
	maxMarginSideAlgorithm string
	//市价单最大下单量
	maxMarketOrderVolume float64
	//限价单最小下单量
	minLimitOrderVolume float64
	//市价单最小下单量
	minMarketOrderVolume float64
	//上市日
	openDate string
	//期权类型
	optionsType string
	//持仓日期类型
	positionDateType string
	//持仓类型
	positionType string
	//最小变动价位
	priceTick float64
	//产品类型
	productClass string
	//产品代码
	productID string
	//空头保证金率
	shortMarginRatio float64
	//开始交割日
	startDelivDate string
	//执行价
	strikePrice float64
	//基础商品代码
	underlyingInstrID string
	//基础商品名称
	underlyingInstrName string
	//合约基础商品乘数
	underlyingMultiple float64
	//合约数量乘数
	volumeMultiple float64
}

//持仓
type InvestorPosition struct{
	//放弃执行冻结
	abandonFrozen float64
	//经纪公司代码
	brokerID string
	//资金差额
	cashIn float64
	//平仓金额
	closeAmount float64
	//平仓盈亏
	closeProfit float64
	//逐日盯市平仓盈亏
	closeProfitByDate float64
	//逐笔对冲平仓盈亏
	closeProfitByTrade float64
	//平仓量
	closeVolume float64
	//合约代码
	code string
	//组合多头冻结
	combLongFrozen float64
	//组合成交形成的持仓
	combPosition float64
	//组合空头冻结
	combShortFrozen float64
	//手续费
	commission float64
	//交易所保证金
	exchangeMargin float64
	//浮动盈亏
	floatProfit float64
	//冻结的资金
	frozenCash float64
	//冻结的手续费
	frozenCommission float64
	//冻结的保证金
	frozenMargin float64
	//投机套保标志
	hedgeFlag string
	//投资者代码
	investorID string
	//多头冻结
	longFrozen float64
	//多头冻结金额
	longFrozenAmount float64
	//保证金
	margin float64
	//保证金率
	marginRateByMoney float64
	//保证金率(按手数)
	marginRateByVolume float64
	//开仓金额
	openAmount float64
	//开仓成本
	openCost float64
	//开仓价格
	openPrice float64
	//开仓量
	openVolume float64
	//今日持仓
	position float64
	//持仓日期
	positionDate string
	//持仓多空方向
	posiDirection string
	//持仓成本
	positionCost float64
	//持仓盈亏
	positionProfit float64
	//上次占用的保证金
	preMargin float64
	//上次结算价
	preSettlementPrice float64
	//结算编号
	settlementID float64
	//本次结算价
	settlementPrice float64
	//空头冻结
	shortFrozen float64
	//空头冻结金额
	shortFrozenAmount float64
	//执行冻结
	strikeFrozen float64
	//执行冻结金额
	strikeFrozenAmount float64
	//今日持仓
	todayPosition float64
	//交易日
	tradingDate string
	//占用的保证金
	useMargin float64
	//上日持仓
	ydPosition float64
}

//持仓明细
type InvestorPositionDetail struct{
	//经纪公司代码
	brokerID string
	//平仓金额
	closeAmount float64
	//平仓盈亏
	closeProfit float64
	//逐日盯市持仓盈亏
	closeProfitByDate float64
	//逐笔对冲持仓盈亏
	closeProfitByTrade float64
	//平仓量
	closeVolume float64
	//合约代码
	code string
	//组合合约代码
	combInstrumentID string
	//买卖
	direction string
	//交易所代码
	exchangeID string
	//交易所保证金
	exchMargin float64
	//浮动盈亏
	floatProfit float64
	//投机套保标志
	hedgeFlag string
	//投资者代码
	investorID string
	//昨收盘
	lastPrice float64
	//昨结算价
	lastSettlementPrice float64
	//投资者保证金
	margin float64
	//保证金率
	marginRateByMoney float64
	//保证金率(按手数)
	marginRateByVolume float64
	//内部编号
	orderRef string
	//开仓日期
	openDate string
	//开仓价
	openPrice float64
	//开仓量
	openVolume float64
	//本地持仓号，服务器编写
	positionNo string
	//持仓盈亏
	positionProfit float64
	//逐日盯市持仓利润
	positionProfitByDate float64
	//逐笔对冲持仓利润
	positionProfitByTrade float64
	//持仓流号
	positionStreamId float64
	//昨结算价
	preSettlementPrice float64
	//持仓盈亏基准价
	profitBasePrice float64
	//结算编号
	settlementID float64
	//结算价
	settlementPrice float64
	//成交日期
	tradingDay string
	//成交编号
	tradeID string
	//成交类型
	tradeType string
	//数量
	volume float64
}

//委托回报
type OrderInfo struct{
	//激活时间
	activeTime string
	//最后修改交易所交易员代码
	activeTraderID string
	//操作用户代码
	activeUserID string
	//经纪公司代码
	brokerID string
	//经纪公司报单编号
	brokerOrderSeq float64
	//业务单元
	businessUnit string
	//撤销时间
	cancelTime string
	//结算会员编号
	clearingPartID string
	//客户代码
	clientID string
	//合约代码
	code string
	//组合投机套保标志
	combHedgeFlag string
	//组合开平标志
	combOffsetFlag string
	//触发条件
	contingentCondition string
	//买卖方向
	direction string
	//交易所代码
	exchangeID string
	//合约在交易所的代码
	exchangeInstID string
	//强平原因
	forceCloseReason string
	//前置编号
	frontID float64
	//GTD日期
	gTDDate string
	//价格
	limitPrice float64
	//报单日期
	insertDate string
	//委托时间
	insertTime string
	//安装编号
	installID string
	//投资者代码
	investorID string
	//自动挂起标志
	isAutoSuspend float64
	//互换单标志
	isSwapOrder float64
	//最小成交量
	minVolume float64
	//报单提示序号
	notifySequence float64
	//本地报单编号
	orderLocalID string
	//报单价格条件
	orderPriceType string
	//报单引用
	orderRef string
	//报单状态
	orderStatus string
	//报单来源
	orderSource string
	//报单提交状态
	orderSubmitStatus string
	//报单编号
	orderSysID string
	//报单类型
	orderType string
	//会员代码
	participantID string
	//相关报单
	relativeOrderSysID string
	//请求编号
	requestID float64
	//序号
	sequenceNo float64
	//会话编号
	sessionID float64
	//结算编号
	settlementID float64
	//状态信息
	statusMsg string
	//止损价
	stopPrice float64
	//挂起时间
	suspendTime string
	//有效期类型
	timeCondition string
	//交易所交易员代码
	traderID string
	//交易日
	tradingDay string
	//最后修改时间
	updateTime string
	//用户强评标志
	userForceClose float64
	//用户代码
	userID string
	//用户端产品信息
	userProductInfo string
	//成交量类型
	volumeCondition string
	//剩余数量
	volumeTotal float64
	//数量
	volumeTotalOriginal float64
	//今成交数量
	volumeTraded float64
	//郑商所成交数量
	zCETotalTradedVolume float64
}

//最新数据
type SecurityLatestData struct{
	//触发日
	actionDay string
	//卖1价
	askPrice1 float64
	//卖2价
	askPrice2 float64
	//卖3价
	askPrice3 float64
	//卖4价
	askPrice4 float64
	//卖5价
	askPrice5 float64
	//卖1量
	askVolume1 int
	//卖2量
	askVolume2 int
	//卖3量
	askVolume3 int
	//卖4量
	askVolume4 int
	//卖5量
	askVolume5 int
	//平均价格
	averagePrice float64
	//买1价
	bidPrice1 float64
	//买2价
	bidPrice2 float64
	//买3价
	bidPrice3 float64
	//买4价
	bidPrice4 float64
	//买5价
	bidPrice5 float64
	//买1量
	bidVolume1 int
	//买2量
	bidVolume2 int
	//买3量
	bidVolume3 int
	//买4量
	bidVolume4 int
	//买5量
	bidVolume5 int
	//最新价
	close float64
	//合约代码
	code string
	//今虚实度
	currDelta float64
	//交易所ID
	exchangeID string
	//交易所InstID
	exchangeInstID string
	//最高价
	high float64
	//昨日收盘价
	lastClose float64
	//最低价
	low float64
	//跌停价
	lowerLimit float64
	//开盘价
	open float64
	//持仓量
	openInterest float64
	//昨收盘
	preClose float64
	//昨虚实度
	preDelta float64
	//昨持仓量
	preOpenInterest float64
	//上次结算价
	preSettlementPrice float64
	//本次结算价
	settlementPrice float64
	//交易日
	tradingDay string
	//成交金额
	turnover float64
	//最后修改毫秒
	updateMillisec float64
	//最后修改时间
	updateTime string
	//涨停价
	upperLimit float64
	//成交量
	volume float64
}

//成交回报
type TradeRecord struct{
	//经纪公司代码
	brokerID string
	///经纪公司报单编号
	brokerOrderSeq float64
	///业务单元
	businessUnit string
	///结算会员编号
	clearingPartID string
	///客户代码
	clientID string
	//合约代码
	code string
	//手续费
	commission float64
	//买卖方向
	direction string
	//市场代码
	exchangeID string
	//合约在交易所的代码
	exchangeInstID string
	//投机套保标志
	hedgeFlag string
	//投资者代码
	investorID string
	//开平标志
	offsetFlag string
	//本地报单编号
	orderLocalID string
	//报单引用
	orderRef string
	//报单编号
	orderSysID string
	//会员代码
	participantID string
	//价格
	price float64
	//成交价来源
	priceSource string
	//序号
	sequenceNo float64
	//结算编号
	settlementID float64
	//成交编号
	tradeID string
	//交易所交易员代码
	traderID string
	//成交时期
	tradeDate string
	//成交来源
	tradeSource string
	//成交时间
	tradeTime string
	//交易日
	tradingDay string
	//成交类型
	tradeType string
	//交易角色
	tradingRole string
	//数量
	volume float64
	//用户代码
	userID string
}

//合约手续费率
type CommissionRate struct{
	//经纪公司代码
	brokerID string
	//收费方式
	calculateMode string
	//平仓手续费率
	closeRatioByMoney float64
	//平仓手续费
	closeRatioByVolume float64
	//平今手续费率
	closeTodayRatioByMoney float64
	//平今手续费
	closeTodayRatioByVolume float64
	//平今费
	closeTodayFee float64
	//合约代码
	code string
	//代码
	commodityNo string
	//类型
	commodityType string
	//交易所编号
	exchangeNo string
	//投资者代码
	investorID string
	//投资者范围
	investorRange string
	//来源
	matchSource string
	//开平费
	openCloseFee float64
	//开仓手续费率
	openRatioByMoney float64
	//开仓手续费
	openRatioByVolume float64
}

//合约保证金率
type MarginRate struct{
	//经纪公司代码
	brokerID string
	//收费方式
	calculateMode string
	//看涨看跌标示
	callOrPutFlag string
	//合约代码
	code string
	//代码
	commodityNo string
	//类型
	commodityType string
	//合约
	contractNo string
	//投机套保标志
	hedgeFlag string
	initialMargin float64
	//投资者代码
	investorID string
	//多头保证金率
	longMarginRatioByMoney float64
	//多头保证金费
	longMarginRatioByVolume float64
	//投资者范围
	investorRange string
	//是否相对交易所收取
	isRelativel float64
	lockMargin float64
	maintenanceMargin float64
	sellInitialMargin float64
	sellMaintenanceMargin float64
	//空头保证金率
	shortMarginRatioByMoney float64
	//空头保证金费
	shortMarginRatioByVolume float64
	strikePrice string
}

//转换成CTP手续费率
func convertToCTPCommissionRate(result string)(CommissionRate){
	cTPCommissionRate := CommissionRate{}
	results := strings.Split(result, ",")
	cTPCommissionRate.code = results[0]
	cTPCommissionRate.investorRange = results[1]
	cTPCommissionRate.brokerID = results[2]
	cTPCommissionRate.investorID = results[3]
	cTPCommissionRate.openRatioByMoney = facecat.ConvertToFloat64(results[4])
	cTPCommissionRate.openRatioByVolume = facecat.ConvertToFloat64(results[5])
	cTPCommissionRate.closeRatioByMoney = facecat.ConvertToFloat64(results[6])
	cTPCommissionRate.closeRatioByVolume = facecat.ConvertToFloat64(results[7])
	cTPCommissionRate.closeTodayRatioByMoney = facecat.ConvertToFloat64(results[8])
	cTPCommissionRate.closeTodayRatioByVolume = facecat.ConvertToFloat64(results[9])
	return cTPCommissionRate
}

//转换CTP保证金率
func convertToCTPMarginRate(result string)(MarginRate){
	cTPMarginRate := MarginRate{}
	results := strings.Split(result, ",")
	cTPMarginRate.code = results[0]
	cTPMarginRate.brokerID = results[1]
	cTPMarginRate.investorID = results[2]
	cTPMarginRate.hedgeFlag = results[3]
	cTPMarginRate.longMarginRatioByMoney = facecat.ConvertToFloat64(results[4])
	cTPMarginRate.longMarginRatioByVolume = facecat.ConvertToFloat64(results[5])
	cTPMarginRate.shortMarginRatioByMoney = facecat.ConvertToFloat64(results[6])
	cTPMarginRate.shortMarginRatioByVolume = facecat.ConvertToFloat64(results[7])
	cTPMarginRate.isRelativel = facecat.ConvertToFloat64(results[8])
	return cTPMarginRate
}

//转换资金账户结构
func convertToCTPAccountData(result string)(AccountData){
	cTPTradingAccount := AccountData{}
	results := strings.Split(result, ",")
	if len(results) >= 46{
		cTPTradingAccount.brokerID = results[0]
		cTPTradingAccount.accountID = results[1]
		cTPTradingAccount.preMortgage = facecat.ConvertToFloat64(results[2])
		cTPTradingAccount.preCredit = facecat.ConvertToFloat64(results[3])
		cTPTradingAccount.preDeposit = facecat.ConvertToFloat64(results[4])
		cTPTradingAccount.preBalance = facecat.ConvertToFloat64(results[5])
		cTPTradingAccount.preMargin = facecat.ConvertToFloat64(results[6])
		cTPTradingAccount.interestBase = facecat.ConvertToFloat64(results[7])
		cTPTradingAccount.interest = facecat.ConvertToFloat64(results[8])
		cTPTradingAccount.deposit = facecat.ConvertToFloat64(results[9])
		cTPTradingAccount.withdraw = facecat.ConvertToFloat64(results[10])
		cTPTradingAccount.frozenMargin = facecat.ConvertToFloat64(results[11])
		cTPTradingAccount.frozenCash = facecat.ConvertToFloat64(results[12])
		cTPTradingAccount.frozenCommission = facecat.ConvertToFloat64(results[13])
		cTPTradingAccount.currMargin = facecat.ConvertToFloat64(results[14])
		cTPTradingAccount.cashIn = facecat.ConvertToFloat64(results[15])
		cTPTradingAccount.commission = facecat.ConvertToFloat64(results[16])
		cTPTradingAccount.closeProfit = facecat.ConvertToFloat64(results[17])
		cTPTradingAccount.positionProfit = facecat.ConvertToFloat64(results[18])
		cTPTradingAccount.balance = facecat.ConvertToFloat64(results[19])
		cTPTradingAccount.available = facecat.ConvertToFloat64(results[20])
		cTPTradingAccount.withdrawQuota = facecat.ConvertToFloat64(results[21])
		cTPTradingAccount.reserve = facecat.ConvertToFloat64(results[22])
		cTPTradingAccount.tradingDay = results[23]
		cTPTradingAccount.settlementID = facecat.ConvertToFloat64(results[24])
		cTPTradingAccount.credit = facecat.ConvertToFloat64(results[25])
		cTPTradingAccount.mortgage = facecat.ConvertToFloat64(results[26])
		cTPTradingAccount.exchangeMargin = facecat.ConvertToFloat64(results[27])
		cTPTradingAccount.deliveryMargin = facecat.ConvertToFloat64(results[28])
		cTPTradingAccount.exchangeDeliveryMargin = facecat.ConvertToFloat64(results[29])
		cTPTradingAccount.reserveBalance = facecat.ConvertToFloat64(results[30])
		cTPTradingAccount.currencyID = results[31]
		cTPTradingAccount.preFundMortgageIn = facecat.ConvertToFloat64(results[32])
		cTPTradingAccount.preFundMortgageOut = facecat.ConvertToFloat64(results[33])
		cTPTradingAccount.fundMortgageIn = facecat.ConvertToFloat64(results[34])
		cTPTradingAccount.fundMortgageOut = facecat.ConvertToFloat64(results[35])
		cTPTradingAccount.fundMortgageAvailable = facecat.ConvertToFloat64(results[36])
		cTPTradingAccount.mortgageableFund = facecat.ConvertToFloat64(results[37])
		cTPTradingAccount.specProductMargin = facecat.ConvertToFloat64(results[38])
		cTPTradingAccount.specProductFrozenMargin = facecat.ConvertToFloat64(results[39])
		cTPTradingAccount.specProductCommission = facecat.ConvertToFloat64(results[40])
		cTPTradingAccount.specProductFrozenCommission = facecat.ConvertToFloat64(results[41])
		cTPTradingAccount.specProductPositionProfit = facecat.ConvertToFloat64(results[42])
		cTPTradingAccount.specProductCloseProfit = facecat.ConvertToFloat64(results[43])
		cTPTradingAccount.specProductPositionProfitByAlg = facecat.ConvertToFloat64(results[44])
		cTPTradingAccount.specProductExchangeMargin = facecat.ConvertToFloat64(results[45])
		cTPTradingAccount.dynamicBalance = facecat.ConvertToFloat64(results[46])
		cTPTradingAccount.risk = facecat.ConvertToFloat64(results[47])
		cTPTradingAccount.floatProfit = facecat.ConvertToFloat64(results[48])
	}
	return cTPTradingAccount
}

//转换深度数据结构
func convertToCTPDepthMarketData(result string)([]SecurityLatestData){
	var list []SecurityLatestData
	strs := strings.Split(result, ";")
	length := len(strs)
	for i := 0; i < length; i++ {
		results := strings.Split(strs[i], ",")
		if len(results) >= 43{
			cTPDepthMarketData := SecurityLatestData{}
			cTPDepthMarketData.tradingDay = results[0]
			cTPDepthMarketData.code = results[1]
			cTPDepthMarketData.exchangeID = results[2]
			cTPDepthMarketData.exchangeInstID = results[3]
			cTPDepthMarketData.close = facecat.ConvertToFloat64(results[4])
			cTPDepthMarketData.preSettlementPrice = facecat.ConvertToFloat64(results[5])
			cTPDepthMarketData.preClose = facecat.ConvertToFloat64(results[6])
			cTPDepthMarketData.preOpenInterest = facecat.ConvertToFloat64(results[7])
			cTPDepthMarketData.open = facecat.ConvertToFloat64(results[8])
			cTPDepthMarketData.high = facecat.ConvertToFloat64(results[9])
			cTPDepthMarketData.low = facecat.ConvertToFloat64(results[10])
			cTPDepthMarketData.volume = facecat.ConvertToFloat64(results[11])
			cTPDepthMarketData.turnover = facecat.ConvertToFloat64(results[12])
			cTPDepthMarketData.openInterest = facecat.ConvertToFloat64(results[13])
			cTPDepthMarketData.lastClose = facecat.ConvertToFloat64(results[14])
			cTPDepthMarketData.settlementPrice = facecat.ConvertToFloat64(results[15])
			cTPDepthMarketData.upperLimit = facecat.ConvertToFloat64(results[16])
			cTPDepthMarketData.lowerLimit = facecat.ConvertToFloat64(results[17])
			cTPDepthMarketData.preDelta = facecat.ConvertToFloat64(results[18])
			cTPDepthMarketData.currDelta = facecat.ConvertToFloat64(results[19])
			cTPDepthMarketData.updateTime = results[20]
			cTPDepthMarketData.updateMillisec = facecat.ConvertToFloat64(results[21])
			cTPDepthMarketData.bidPrice1 = facecat.ConvertToFloat64(results[22])
			cTPDepthMarketData.bidVolume1 = facecat.ConvertToInt(results[23])
			cTPDepthMarketData.askPrice1 = facecat.ConvertToFloat64(results[24])
			cTPDepthMarketData.askVolume1 = facecat.ConvertToInt(results[25])
			cTPDepthMarketData.bidPrice2 = facecat.ConvertToFloat64(results[26])
			cTPDepthMarketData.bidVolume2 = facecat.ConvertToInt(results[27])
			cTPDepthMarketData.askPrice2 = facecat.ConvertToFloat64(results[28])
			cTPDepthMarketData.askVolume2 = facecat.ConvertToInt(results[29])
			cTPDepthMarketData.bidPrice3 = facecat.ConvertToFloat64(results[30])
			cTPDepthMarketData.bidVolume3 = facecat.ConvertToInt(results[31])
			cTPDepthMarketData.askPrice3 = facecat.ConvertToFloat64(results[32])
			cTPDepthMarketData.askVolume3 = facecat.ConvertToInt(results[33])
			cTPDepthMarketData.bidPrice4 = facecat.ConvertToFloat64(results[34])
			cTPDepthMarketData.bidVolume4 = facecat.ConvertToInt(results[35])
			cTPDepthMarketData.askPrice4 = facecat.ConvertToFloat64(results[36])
			cTPDepthMarketData.askVolume4 = facecat.ConvertToInt(results[37])
			cTPDepthMarketData.bidPrice5 = facecat.ConvertToFloat64(results[38])
			cTPDepthMarketData.bidVolume5 = facecat.ConvertToInt(results[39])
			cTPDepthMarketData.askPrice5 = facecat.ConvertToFloat64(results[40])
			cTPDepthMarketData.askVolume5 = facecat.ConvertToInt(results[41])
			cTPDepthMarketData.averagePrice = facecat.ConvertToFloat64(results[42])
			cTPDepthMarketData.actionDay = results[43]
			list = append(list, cTPDepthMarketData)
		}
	}
	return list
}

//转换期货信息结构
func convertToCTPInstrumentDatas(result string)([]Security){
	var cTPInstrumentDatas []Security
	strs := strings.Split(result, ";")
	length := len(strs)
	for i := 0; i < length; i++ {
		results := strings.Split(strs[i], ",")
		if len(results) >= 30{
			cTPInstrumentData := Security{}
			cTPInstrumentData.instrumentID = results[0]
			cTPInstrumentData.exchangeID = results[1]
			cTPInstrumentData.instrumentName = results[2]
			cTPInstrumentData.exchangeInstID = results[3]
			cTPInstrumentData.productID = results[4]
			cTPInstrumentData.productClass = results[5]
			cTPInstrumentData.deliveryYear = facecat.ConvertToFloat64(results[6])
			cTPInstrumentData.deliveryMonth = facecat.ConvertToFloat64(results[7])
			cTPInstrumentData.maxMarketOrderVolume = facecat.ConvertToFloat64(results[8])
			cTPInstrumentData.minMarketOrderVolume = facecat.ConvertToFloat64(results[9])
			cTPInstrumentData.maxLimitOrderVolume = facecat.ConvertToFloat64(results[10])
			cTPInstrumentData.minLimitOrderVolume = facecat.ConvertToFloat64(results[11])
			cTPInstrumentData.volumeMultiple = facecat.ConvertToFloat64(results[12])
			cTPInstrumentData.priceTick = facecat.ConvertToFloat64(results[13])
			cTPInstrumentData.createDate = results[14]
			cTPInstrumentData.openDate = results[15]
			cTPInstrumentData.expireDate = results[16]
			cTPInstrumentData.startDelivDate = results[17]
			cTPInstrumentData.endDelivDate = results[18]
			cTPInstrumentData.instLifePhase = results[19]
			cTPInstrumentData.isTrading = results[20]
			cTPInstrumentData.positionType = results[21]
			cTPInstrumentData.positionDateType = results[22]
			cTPInstrumentData.longMarginRatio = facecat.ConvertToFloat64(results[23])
			cTPInstrumentData.shortMarginRatio = facecat.ConvertToFloat64(results[24])
			cTPInstrumentData.maxMarginSideAlgorithm = results[25]
			cTPInstrumentData.underlyingInstrID = results[26]
			cTPInstrumentData.strikePrice = facecat.ConvertToFloat64(results[27])
			cTPInstrumentData.optionsType = results[28]
			cTPInstrumentData.underlyingMultiple = facecat.ConvertToFloat64(results[29])
			cTPInstrumentData.combinationType = results[30]
			cTPInstrumentDatas = append(cTPInstrumentDatas, cTPInstrumentData)
		}
	}
	return cTPInstrumentDatas
}

//转换持仓结构
func convertToCTPInvestorPosition(result string)([]InvestorPosition){
	var list []InvestorPosition
	strs := strings.Split(result, ";")
	length := len(strs)
	for i := 0; i < length; i++ {
		results := strings.Split(strs[i], ",")
		if len(results) >= 42{
			cTPInvestorPosition := InvestorPosition{}
			cTPInvestorPosition.code = results[0]
			cTPInvestorPosition.brokerID = results[1]
			cTPInvestorPosition.investorID = results[2]
			cTPInvestorPosition.posiDirection = results[3]
			cTPInvestorPosition.hedgeFlag = results[4]
			cTPInvestorPosition.positionDate = results[5]
			cTPInvestorPosition.ydPosition = facecat.ConvertToFloat64(results[6])
			cTPInvestorPosition.position = facecat.ConvertToFloat64(results[7])
			cTPInvestorPosition.longFrozen = facecat.ConvertToFloat64(results[8])
			cTPInvestorPosition.shortFrozen = facecat.ConvertToFloat64(results[9])
			cTPInvestorPosition.longFrozenAmount = facecat.ConvertToFloat64(results[10])
			cTPInvestorPosition.shortFrozenAmount = facecat.ConvertToFloat64(results[11])
			cTPInvestorPosition.openVolume = facecat.ConvertToFloat64(results[12])
			cTPInvestorPosition.closeVolume = facecat.ConvertToFloat64(results[13])
			cTPInvestorPosition.openAmount = facecat.ConvertToFloat64(results[14])
			cTPInvestorPosition.closeAmount = facecat.ConvertToFloat64(results[15])
			cTPInvestorPosition.positionCost = facecat.ConvertToFloat64(results[16])
			cTPInvestorPosition.preMargin = facecat.ConvertToFloat64(results[17])
			cTPInvestorPosition.useMargin = facecat.ConvertToFloat64(results[18])
			cTPInvestorPosition.frozenMargin = facecat.ConvertToFloat64(results[19])
			cTPInvestorPosition.frozenCash = facecat.ConvertToFloat64(results[20])
			cTPInvestorPosition.frozenCommission = facecat.ConvertToFloat64(results[21])
			cTPInvestorPosition.cashIn = facecat.ConvertToFloat64(results[22])
			cTPInvestorPosition.margin = facecat.ConvertToFloat64(results[23])
			cTPInvestorPosition.floatProfit = facecat.ConvertToFloat64(results[24])
			cTPInvestorPosition.positionProfit = facecat.ConvertToFloat64(results[25])
			cTPInvestorPosition.preSettlementPrice = facecat.ConvertToFloat64(results[26])
			cTPInvestorPosition.settlementPrice = facecat.ConvertToFloat64(results[27])
			cTPInvestorPosition.tradingDate = results[28]
			cTPInvestorPosition.settlementID = facecat.ConvertToFloat64(results[29])
			cTPInvestorPosition.openCost = facecat.ConvertToFloat64(results[30])
			cTPInvestorPosition.exchangeMargin = facecat.ConvertToFloat64(results[31])
			cTPInvestorPosition.combPosition = facecat.ConvertToFloat64(results[32])
			cTPInvestorPosition.combLongFrozen = facecat.ConvertToFloat64(results[33])
			cTPInvestorPosition.combShortFrozen = facecat.ConvertToFloat64(results[34])
			cTPInvestorPosition.closeProfitByDate = facecat.ConvertToFloat64(results[35])
			cTPInvestorPosition.closeProfitByTrade = facecat.ConvertToFloat64(results[36])
			cTPInvestorPosition.todayPosition = facecat.ConvertToFloat64(results[37])
			cTPInvestorPosition.marginRateByMoney = facecat.ConvertToFloat64(results[38])
			cTPInvestorPosition.marginRateByVolume = facecat.ConvertToFloat64(results[39])
			cTPInvestorPosition.strikeFrozen = facecat.ConvertToFloat64(results[40])
			cTPInvestorPosition.strikeFrozenAmount = facecat.ConvertToFloat64(results[41])
			cTPInvestorPosition.abandonFrozen = facecat.ConvertToFloat64(results[42])
			cTPInvestorPosition.openPrice = facecat.ConvertToFloat64(results[43])
			list = append(list, cTPInvestorPosition)
		}
	}
	return list
}

//转换持仓明细结构
func convertToCTPInvestorPositionDetail(result string)([]InvestorPositionDetail){
	var list []InvestorPositionDetail
	strs := strings.Split(result, ";")
	length := len(strs)
	for i := 0; i < length; i++ {
		results := strings.Split(strs[i], ",")
		if len(results) >= 25{
			cTPInvestorPositionDetail := InvestorPositionDetail{}
			cTPInvestorPositionDetail.code = results[0]
			cTPInvestorPositionDetail.brokerID = results[1]
			cTPInvestorPositionDetail.investorID = results[2]
			cTPInvestorPositionDetail.hedgeFlag = results[3]
			cTPInvestorPositionDetail.direction = results[4]
			cTPInvestorPositionDetail.openDate = results[5]
			cTPInvestorPositionDetail.tradeID = results[6]
			cTPInvestorPositionDetail.volume = facecat.ConvertToFloat64(results[7])
			cTPInvestorPositionDetail.openPrice = facecat.ConvertToFloat64(results[8])
			cTPInvestorPositionDetail.tradingDay = results[9]
			cTPInvestorPositionDetail.settlementID = facecat.ConvertToFloat64(results[10])
			cTPInvestorPositionDetail.tradeType = results[11]
			cTPInvestorPositionDetail.combInstrumentID = results[12]
			cTPInvestorPositionDetail.exchangeID = results[13]
			cTPInvestorPositionDetail.closeProfitByDate = facecat.ConvertToFloat64(results[14])
			cTPInvestorPositionDetail.closeProfitByTrade = facecat.ConvertToFloat64(results[15])
			cTPInvestorPositionDetail.positionProfitByDate = facecat.ConvertToFloat64(results[16])
			cTPInvestorPositionDetail.positionProfitByTrade = facecat.ConvertToFloat64(results[17])
			cTPInvestorPositionDetail.margin = facecat.ConvertToFloat64(results[18])
			cTPInvestorPositionDetail.exchMargin = facecat.ConvertToFloat64(results[19])
			cTPInvestorPositionDetail.marginRateByMoney = facecat.ConvertToFloat64(results[20])
			cTPInvestorPositionDetail.marginRateByVolume = facecat.ConvertToFloat64(results[21])
			cTPInvestorPositionDetail.lastSettlementPrice = facecat.ConvertToFloat64(results[22])
			cTPInvestorPositionDetail.lastSettlementPrice = facecat.ConvertToFloat64(results[23])
			cTPInvestorPositionDetail.settlementPrice = facecat.ConvertToFloat64(results[24])
			cTPInvestorPositionDetail.closeVolume = facecat.ConvertToFloat64(results[25])
			list = append(list, cTPInvestorPositionDetail)
		}
	}
	return list
}

//转换成委托回报结构
func convertToCTPOrder(result string)(OrderInfo){
	cTPOrder := OrderInfo{}
	results := strings.Split(result, ",")
	if len(results) >= 56{
		cTPOrder.brokerID = results[0]
		cTPOrder.investorID = results[1]
		cTPOrder.code = results[2]
		cTPOrder.orderRef = results[3]
		cTPOrder.userID = results[4]
		cTPOrder.orderPriceType = results[5]
		cTPOrder.direction = results[6]
		cTPOrder.combOffsetFlag = results[7]
		cTPOrder.combHedgeFlag = results[8]
		cTPOrder.limitPrice = facecat.ConvertToFloat64(results[9])
		cTPOrder.volumeTotalOriginal = facecat.ConvertToFloat64(results[10])
		cTPOrder.timeCondition = results[11]
		cTPOrder.gTDDate = results[12]
		cTPOrder.volumeCondition = results[13]
		cTPOrder.minVolume = facecat.ConvertToFloat64(results[14])
		cTPOrder.contingentCondition = results[15]
		cTPOrder.stopPrice = facecat.ConvertToFloat64(results[16])
		cTPOrder.forceCloseReason = results[17]
		cTPOrder.isAutoSuspend = facecat.ConvertToFloat64(results[18])
		cTPOrder.businessUnit = results[19]
		cTPOrder.requestID = facecat.ConvertToFloat64(results[20])
		cTPOrder.orderLocalID = results[21]
		cTPOrder.exchangeID = results[22]
		cTPOrder.participantID = results[23]
		cTPOrder.clientID = results[24]
		cTPOrder.exchangeInstID = results[25]
		cTPOrder.traderID = results[26]
		cTPOrder.installID = results[27]
		cTPOrder.orderSubmitStatus = results[28]
		cTPOrder.notifySequence = facecat.ConvertToFloat64(results[29])
		cTPOrder.tradingDay = results[30]
		cTPOrder.settlementID = facecat.ConvertToFloat64(results[31])
		cTPOrder.orderSysID = results[32]
		cTPOrder.orderSource = results[33]
		cTPOrder.orderStatus = results[34]
		cTPOrder.orderType = results[35]
		cTPOrder.volumeTraded = facecat.ConvertToFloat64(results[36])
		cTPOrder.volumeTotal = facecat.ConvertToFloat64(results[37])
		cTPOrder.insertDate = results[38]
		cTPOrder.insertTime = results[39]
		cTPOrder.activeTime = results[40]
		cTPOrder.suspendTime = results[41]
		cTPOrder.updateTime = results[42]
		cTPOrder.cancelTime = results[43]
		cTPOrder.activeTraderID = results[44]
		cTPOrder.clearingPartID = results[45]
		cTPOrder.sequenceNo = facecat.ConvertToFloat64(results[46])
		cTPOrder.frontID = facecat.ConvertToFloat64(results[47])
		cTPOrder.sessionID = facecat.ConvertToFloat64(results[48])
		cTPOrder.userProductInfo = results[49]
		cTPOrder.statusMsg = results[50]
		cTPOrder.userForceClose = facecat.ConvertToFloat64(results[51])
		cTPOrder.activeUserID = results[52]
		cTPOrder.brokerOrderSeq = facecat.ConvertToFloat64(results[53])
		cTPOrder.relativeOrderSysID = results[54]
		cTPOrder.zCETotalTradedVolume = facecat.ConvertToFloat64(results[55])
		cTPOrder.isSwapOrder = facecat.ConvertToFloat64(results[56])
	}
	return cTPOrder
}

//转换持仓明细结构
func convertToCTPOrderList(result string)([]OrderInfo){
	var lst []OrderInfo
	strs := strings.Split(result, ";")
	length := len(strs)
	for i := 0; i < length; i++ {
		lst = append(lst, convertToCTPOrder(strs[i]))
	}
	return lst
}

//转换成成交回报结构
func convertToCTPTrade(result string)(TradeRecord){
	cTPTrade := TradeRecord{}
	results := strings.Split(result, ",")
	if len(results) > 30{
		cTPTrade.brokerID = results[0]
		cTPTrade.investorID = results[1]
		cTPTrade.code = results[2]
		cTPTrade.orderRef = results[3]
		cTPTrade.userID = results[4]
		cTPTrade.exchangeID = results[5]
		cTPTrade.tradeID = results[6]
		cTPTrade.direction = results[7]
		cTPTrade.orderSysID = results[8]
		cTPTrade.participantID = results[9]
		cTPTrade.clientID = results[10]
		cTPTrade.tradingRole = results[11]
		cTPTrade.exchangeInstID = results[12]
		cTPTrade.offsetFlag = results[13]
		cTPTrade.hedgeFlag = results[14]
		cTPTrade.price = facecat.ConvertToFloat64(results[15])
		cTPTrade.volume = facecat.ConvertToFloat64(results[16])
		cTPTrade.tradeDate = results[17]
		cTPTrade.tradeTime = results[18]
		cTPTrade.tradeType = results[19]
		cTPTrade.priceSource = results[20]
		cTPTrade.traderID = results[21]
		cTPTrade.orderLocalID = results[22]
		cTPTrade.clearingPartID = results[23]
		cTPTrade.businessUnit = results[24]
		cTPTrade.sequenceNo = facecat.ConvertToFloat64(results[25])
		cTPTrade.tradingDay = results[26]
		cTPTrade.settlementID = facecat.ConvertToFloat64(results[27])
		cTPTrade.brokerOrderSeq = facecat.ConvertToFloat64(results[28])
		cTPTrade.tradeSource = results[29]
		cTPTrade.commission = facecat.ConvertToFloat64(results[30])
	}
	return cTPTrade
}

//转换成成交回报列表
func convertToCTPTradeRecords(result string)([]TradeRecord){
	var lst []TradeRecord
	strs := strings.Split(result, ";")
	length := len(strs)
	for i := 0; i < length; i++ {
		lst = append(lst, convertToCTPTrade(strs[i]))
	}
	return lst
}

//卖平：多单平仓
//ctpID ctp编号
//requestID 请求ID
//code 代码
//exchangeID 交易所ID
//price 价格
//qty 数量
//timeCondition 有效期
//orderRef 附加信息
func ctp_setEncoding(encoding int)(int){
	result,_,_ := procSetEncoding.Call(facecat.IntToPtr(encoding))
	return int(result)
}

//卖平：多单平仓
//ctpID ctp编号
//requestID 请求ID
//code 代码
//exchangeID 交易所ID
//price 价格
//qty 数量
//timeCondition 有效期
//orderRef 附加信息
func ctp_askClose(ctpID int, requestID int, code string, exchangeID string, price float64, qty int, timeCondition int, orderRef string)(int){
	strPrice := facecat.ConvertFloat64ToStr(price)
	result,_,_ := procAskClose2.Call(facecat.IntToPtr(ctpID), facecat.IntToPtr(requestID), facecat.StringToUintPtr(code), facecat.StringToUintPtr(exchangeID), facecat.StringToUintPtr(strPrice), facecat.IntToPtr(qty), facecat.IntToPtr(timeCondition), facecat.StringToUintPtr(orderRef))
	return int(result)
}

//卖平今仓：平今天的开仓的空单
//ctpID ctp编号
//requestID 请求ID
//code 代码
//exchangeID 交易所ID
//price 价格
//qty 数量
//timeCondition 有效期
//orderRef 附加信息
func ctp_askCloseToday(ctpID int, requestID int, code string, exchangeID string, price float64, qty int, timeCondition int, orderRef string)(int){
	strPrice := facecat.ConvertFloat64ToStr(price)
	result,_,_ := procAskCloseToday2.Call(facecat.IntToPtr(ctpID), facecat.IntToPtr(requestID), facecat.StringToUintPtr(code), facecat.StringToUintPtr(exchangeID), facecat.StringToUintPtr(strPrice), facecat.IntToPtr(qty), facecat.IntToPtr(timeCondition), facecat.StringToUintPtr(orderRef))
	return int(result)
}

//卖开：空单开仓
//ctpID ctp编号
//requestID 请求ID
//code 代码
//exchangeID 交易所ID
//price 价格
//qty 数量
//timeCondition 有效期
//orderRef 附加信息
func ctp_askOpen(ctpID int, requestID int, code string, exchangeID string, price float64, qty int, timeCondition int, orderRef string)(int){
	strPrice := facecat.ConvertFloat64ToStr(price)
	result,_,_ := procAskOpen2.Call(facecat.IntToPtr(ctpID), facecat.IntToPtr(requestID), facecat.StringToUintPtr(code), facecat.StringToUintPtr(exchangeID), facecat.StringToUintPtr(strPrice), facecat.IntToPtr(qty), facecat.IntToPtr(timeCondition), facecat.StringToUintPtr(orderRef))
	return int(result)
}

//买平：空单平仓
//ctpID ctp编号
//requestID 请求ID
//code 代码
//exchangeID 交易所ID
//price 价格
//qty 数量
//timeCondition 有效期
//orderRef 附加信息
func ctp_bidClose(ctpID int, requestID int, code string, exchangeID string, price float64, qty int, timeCondition int, orderRef string)(int){
	strPrice := facecat.ConvertFloat64ToStr(price)
	result,_,_ := procBidClose2.Call(facecat.IntToPtr(ctpID), facecat.IntToPtr(requestID), facecat.StringToUintPtr(code), facecat.StringToUintPtr(exchangeID), facecat.StringToUintPtr(strPrice), facecat.IntToPtr(qty), facecat.IntToPtr(timeCondition), facecat.StringToUintPtr(orderRef))
	return int(result)
}

//买平今仓：平今天的开仓的空单
//ctpID ctp编号
//requestID 请求ID
//code 代码
//exchangeID 交易所ID
//price 价格
//qty 数量
//timeCondition 有效期
//orderRef 附加信息
func ctp_bidCloseToday(ctpID int, requestID int, code string, exchangeID string, price float64, qty int, timeCondition int, orderRef string)(int){
	strPrice := facecat.ConvertFloat64ToStr(price)
	result,_,_ := procBidCloseToday2.Call(facecat.IntToPtr(ctpID), facecat.IntToPtr(requestID), facecat.StringToUintPtr(code), facecat.StringToUintPtr(exchangeID), facecat.StringToUintPtr(strPrice), facecat.IntToPtr(qty), facecat.IntToPtr(timeCondition), facecat.StringToUintPtr(orderRef))
	return int(result)
}

//买开：多单开仓
//ctpID ctp编号
//requestID 请求ID
//code 代码
//exchangeID 交易所ID
//price 价格
//qty 数量
//timeCondition 有效期
//orderRef 附加信息
func ctp_bidOpen(ctpID int, requestID int, code string, exchangeID string, price float64, qty int, timeCondition int, orderRef string)(int){
	strPrice := facecat.ConvertFloat64ToStr(price)
	result,_,_ := procBidOpen2.Call(facecat.IntToPtr(ctpID), facecat.IntToPtr(requestID), facecat.StringToUintPtr(code), facecat.StringToUintPtr(exchangeID), facecat.StringToUintPtr(strPrice), facecat.IntToPtr(qty), facecat.IntToPtr(timeCondition), facecat.StringToUintPtr(orderRef))
	return int(result)
}

//撤单
//ctpID ctp编号
//requestID 请求ID
//exchangeID 交易所ID
//orderSysID 委托编号
//orderRef 附加信息
func ctp_cancelOrder(ctpID int, requestID int, exchangeID string, orderSysID string, orderRef string)(int){
	result,_,_ := procCancelOrder.Call(facecat.IntToPtr(ctpID), facecat.IntToPtr(requestID), facecat.StringToUintPtr(exchangeID), facecat.StringToUintPtr(orderSysID), facecat.StringToUintPtr(orderRef))
	return int(result)
}

//创建交易
func ctp_create()(int){
	result,_,_ := procCreate.Call()
	return int(result)
}

//生成ctp请求编号
//ctpID ctp编号
func ctp_generateReqID(ctpID int)(int){
	result,_,_ := procGenerateReqID.Call(facecat.IntToPtr(ctpID))
	return int(result)
}

//是否有新的数据
//ctpID ctp编号
func ctp_hasNewDatas(ctpID int)(bool){
	result,_,_ := procHasNewDatas.Call(facecat.IntToPtr(ctpID))
	return facecat.GoBool(result)
}

//获取资金账户信息
//ctpID ctp编号
func ctp_getAccountData(ctpID int)(string){
	var bytes [1024000]byte
	var c *byte = &bytes[0]
	ptr := uintptr(unsafe.Pointer(uintptr(unsafe.Pointer(c)) + uintptr(1)))
	procGetAccountData.Call(facecat.IntToPtr(ctpID), ptr)
	return facecat.StringFromPtr(ptr)
}

//获取经纪公司ID
//ctpID ctp编号
func ctp_getBrokerID(ctpID int)(string){
	var bytes [1024000]byte
	var c *byte = &bytes[0]
	ptr := uintptr(unsafe.Pointer(uintptr(unsafe.Pointer(c)) + uintptr(1)))
	procGetBrokerID.Call(facecat.IntToPtr(ctpID), ptr)
	return facecat.StringFromPtr(ptr)
}

//获取手续费率
//ctpID ctp编号
//code 代码
func ctp_getCommissionRate(ctpID int, code string)(string){
	var bytes [1024000]byte
	var c *byte = &bytes[0]
	ptr := uintptr(unsafe.Pointer(uintptr(unsafe.Pointer(c)) + uintptr(1)))
	procGetCommissionRate.Call(facecat.IntToPtr(ctpID), facecat.StringToUintPtr(code), ptr)
	return facecat.StringFromPtr(ptr)
}

//获取深度市场行情
//ctpID ctp编号
func ctp_getDepthMarketData(ctpID int)(string){
	var bytes [1024000]byte
	var c *byte = &bytes[0]
	ptr := uintptr(unsafe.Pointer(uintptr(unsafe.Pointer(c)) + uintptr(1)))
	procGetDepthMarketData.Call(facecat.IntToPtr(ctpID), ptr)
	return facecat.StringFromPtr(ptr)
}

//获取合约数据
//ctpID ctp编号
func ctp_getInstrumentsData(ctpID int)(string){
	var bytes [1024000]byte
	var c *byte = &bytes[0]
	ptr := uintptr(unsafe.Pointer(uintptr(unsafe.Pointer(c)) + uintptr(1)))
	procGetInstrumentsData.Call(facecat.IntToPtr(ctpID), ptr)
	return facecat.StringFromPtr(ptr)
}

//获取投资者ID
//ctpID ctp编号
func ctp_getInvestorID(ctpID int)(string){
	var bytes [1024000]byte
	var c *byte = &bytes[0]
	ptr := uintptr(unsafe.Pointer(uintptr(unsafe.Pointer(c)) + uintptr(1)))
	procGetInvestorID.Call(facecat.IntToPtr(ctpID), ptr)
	return facecat.StringFromPtr(ptr)
}

//获取保证金率
//ctpID ctp编号
//code 代码
func ctp_getMarginRate(ctpID int, code string)(string){
	var bytes [1024000]byte
	var c *byte = &bytes[0]
	ptr := uintptr(unsafe.Pointer(uintptr(unsafe.Pointer(c)) + uintptr(1)))
	procGetMarginRate.Call(facecat.IntToPtr(ctpID), facecat.StringToUintPtr(code), ptr)
	return facecat.StringFromPtr(ptr)
}

//获取投资者持仓数据
//ctpID ctp编号
func ctp_getPositionData(ctpID int)(string){
	var bytes [1024000]byte
	var c *byte = &bytes[0]
	ptr := uintptr(unsafe.Pointer(uintptr(unsafe.Pointer(c)) + uintptr(1)))
	procGetPositionData.Call(facecat.IntToPtr(ctpID), ptr)
	return facecat.StringFromPtr(ptr)
}

//获取投资者持仓明细数据
//ctpID ctp编号
func ctp_getPositionDetailData(ctpID int)(string){
	var bytes [1024000]byte
	var c *byte = &bytes[0]
	ptr := uintptr(unsafe.Pointer(uintptr(unsafe.Pointer(c)) + uintptr(1)))
	procGetPositionDetailData.Call(facecat.IntToPtr(ctpID), ptr)
	return facecat.StringFromPtr(ptr)
}

//获取最新的委托回报（上一条）
//ctpID ctp编号
func ctp_getOrderInfo(ctpID int)(string){
	var bytes [1024000]byte
	var c *byte = &bytes[0]
	ptr := uintptr(unsafe.Pointer(uintptr(unsafe.Pointer(c)) + uintptr(1)))
	procGetOrderInfo.Call(facecat.IntToPtr(ctpID), ptr)
	return facecat.StringFromPtr(ptr)
}

//获取所有的最新委托回报（今天的所有委托）
//ctpID ctp编号
func ctp_getOrderInfos(ctpID int)(string){
	var bytes [1024000]byte
	var c *byte = &bytes[0]
	ptr := uintptr(unsafe.Pointer(uintptr(unsafe.Pointer(c)) + uintptr(1)))
	procGetOrderInfos.Call(facecat.IntToPtr(ctpID), ptr)
	return facecat.StringFromPtr(ptr)
}

//获取sessionID
//ctpID ctp编号
func ctp_getSessionID(ctpID int)(int){
	result,_,_ := procGetSessionID.Call(facecat.IntToPtr(ctpID))
	return int(result)
}

//获取结算单信息
//ctpID ctp编号
func ctp_getSettlementInfo(ctpID int)(string){
	var bytes [1024000]byte
	var c *byte = &bytes[0]
	ptr := uintptr(unsafe.Pointer(uintptr(unsafe.Pointer(c)) + uintptr(1)))
	procGetSettlementInfo.Call(facecat.IntToPtr(ctpID), ptr)
	return facecat.StringFromPtr(ptr)
}

//获取最新成交记录（上一条） 
//ctpID ctp编号
func ctp_getTradeRecord(ctpID int)(string){
	var bytes [1024000]byte
	var c *byte = &bytes[0]
	ptr := uintptr(unsafe.Pointer(uintptr(unsafe.Pointer(c)) + uintptr(1)))
	procGetTradeRecord.Call(facecat.IntToPtr(ctpID), ptr)
	return facecat.StringFromPtr(ptr)
}

//获取最新交易记录（今天的所有交易）
//ctpID ctp编号
func ctp_getTradeRecords(ctpID int)(string){
	var bytes [1024000]byte
	var c *byte = &bytes[0]
	ptr := uintptr(unsafe.Pointer(uintptr(unsafe.Pointer(c)) + uintptr(1)))
	procGetTradeRecords.Call(facecat.IntToPtr(ctpID), ptr)
	return facecat.StringFromPtr(ptr)
}

//获取交易日期
//ctpID ctp编号
func ctp_getTradingDate(ctpID int)(string){
	var bytes [1024000]byte
	var c *byte = &bytes[0]
	ptr := uintptr(unsafe.Pointer(uintptr(unsafe.Pointer(c)) + uintptr(1)))
	procGetTradingDate.Call(facecat.IntToPtr(ctpID), ptr)
	return facecat.StringFromPtr(ptr)
}

//获取交易时间
//ctpID ctp编号
func ctp_getTradingTime(ctpID int)(string){
	var bytes [1024000]byte
	var c *byte = &bytes[0]
	ptr := uintptr(unsafe.Pointer(uintptr(unsafe.Pointer(c)) + uintptr(1)))
	procGetTradingTime.Call(facecat.IntToPtr(ctpID), ptr)
	return facecat.StringFromPtr(ptr)
}

//当天是否已经结算
//ctpID ctp编号
func ctp_isClearanced(ctpID int)(bool){
	result,_,_ := procIsClearanced.Call(facecat.IntToPtr(ctpID))
	return facecat.GoBool(result)
}

//是否是结算时间
//ctpID ctp编号
func ctp_isClearanceTime(ctpID int)(bool){
	result,_,_ := procIsClearanceTime.Call(facecat.IntToPtr(ctpID))
	return facecat.GoBool(result)
}

//数据是否准备好
//ctpID ctp编号
func ctp_isDataOk(ctpID int)(bool){
	result,_,_ := procIsDataOk.Call(facecat.IntToPtr(ctpID))
	return facecat.GoBool(result)
}

//行情数据服务器是否已经登录
//ctpID ctp编号
func ctp_isMdLogined(ctpID int)(bool){
	result,_,_ := procIsMdLogined.Call(facecat.IntToPtr(ctpID))
	return facecat.GoBool(result)
}

//交易是否已经登录
//ctpID ctp编号
func ctp_isTdLogined(ctpID int)(bool){
	result,_,_ := procIsTdLogined.Call(facecat.IntToPtr(ctpID))
	return facecat.GoBool(result)
}

//是否是交易时间
//ctpID ctp编号
func ctp_isTradingTime(ctpID int)(bool){
	result,_,_ := procIsTradingTime.Call(facecat.IntToPtr(ctpID))
	return facecat.GoBool(result)
}

//是否是精确交易时间(去掉集合竞价时间和休息时间)
//ctpID ctp编号
//code 代码
func ctp_isTradingTimeExact(ctpID int, code string)(bool){
	result,_,_ := procIsTradingTimeExact.Call(facecat.IntToPtr(ctpID), facecat.StringToUintPtr(code))
	return facecat.GoBool(result)
}

//请求手续费率
//ctpID ctp编号
//code 代码
//requestID 请求ID
func ctp_reqCommissionRate(ctpID int, code string, requestID int)(int){
	result,_,_ := procReqCommissionRate.Call(facecat.IntToPtr(ctpID), facecat.StringToUintPtr(code), facecat.IntToPtr(requestID))
	return int(result)
}

//请求确认结算信息
//ctpID ctp编号
//requestID 请求ID
func ctp_reqQrySettlementInfoConfirm(ctpID int, requestID int)(int){
	result,_,_ := procReqQrySettlementInfoConfirm.Call(facecat.IntToPtr(ctpID), facecat.IntToPtr(requestID))
	return int(result)
}

//请求确认结算信息
//ctpID ctp编号
//requestID 请求ID
//tradingDay 交易日
func ctp_reqQrySettlementInfo(ctpID int, requestID int, tradingDay string)(int){
	result,_,_ := procReqQrySettlementInfo.Call(facecat.IntToPtr(ctpID), facecat.IntToPtr(requestID), facecat.StringToUintPtr(tradingDay))
	return int(result)
}

//请求保证金率
//ctpID ctp编号
//code 代码
//requestID 请求ID
func ctp_reqMarginRate(ctpID int, code string, requestID int)(int){
	result,_,_ := procReqMarginRate.Call(facecat.IntToPtr(ctpID), facecat.StringToUintPtr(code), facecat.IntToPtr(requestID))
	return int(result)
}

//启动创建的连接(在create后执行)
//ctpID ctp编号
//requestID 请求ID
//appID APPID
//authCode 用户ID
//mdServer 行情地址
//tdServer 交易地址
//brokerID 机构号
//investorID 投资者账号
//password 密码
func ctp_start(ctpID int, requestID int, appID string, authCode string, mdServer string, tdServer string, brokerID string, investorID string, password string)(int){
	result,_,_ := procStart.Call(facecat.IntToPtr(ctpID), facecat.IntToPtr(requestID), facecat.StringToUintPtr(appID), facecat.StringToUintPtr(authCode), facecat.StringToUintPtr(mdServer), facecat.StringToUintPtr(tdServer), facecat.StringToUintPtr(brokerID), facecat.StringToUintPtr(investorID), facecat.StringToUintPtr(password))
	return int(result)
}

//订阅多个合约的行情数据
//ctpID ctp编号
//requestID 请求ID
//code 代码
func ctp_subMarketDatas(ctpID int, requestID int, code string)(int){
	result,_,_ := procSubMarketDatas.Call(facecat.IntToPtr(ctpID), facecat.IntToPtr(requestID), facecat.StringToUintPtr(code))
	return int(result)
}

//取消订阅多个合约的行情数据
//ctpID ctp编号
//requestID 请求ID
//code 代码
func ctp_unSubMarketDatas(ctpID int, requestID int, code string)(int){
	result,_,_ := procUnSubMarketDatas.Call(facecat.IntToPtr(ctpID), facecat.IntToPtr(requestID), facecat.StringToUintPtr(code))
	return int(result)
}

//设置消息回调
//ctpID ctp编号
//hWnd 句柄
//msgID 消息ID
func ctp_setMessageID(ctpID int, hWnd int, msgID int)(int){
	result,_,_ := procSetMessageID.Call(facecat.IntToPtr(ctpID), facecat.IntToPtr(hWnd), facecat.IntToPtr(msgID))
	return int(result)
}

/*
* 重绘背景的实现方法
* view:视图
* paint:绘图对象
* clipRect:裁剪区域
*/
func OnPaint(view *facecat.FCView, paint *facecat.FCPaint, clipRect facecat.FCRect) {
    facecat.OnPaintDefault(view, paint, clipRect)
}

/*
* 重绘边框的实现方法
* view:视图
* paint:绘图对象
* clipRect:裁剪区域
*/
func OnPaintBorder(view *facecat.FCView, paint *facecat.FCPaint, clipRect facecat.FCRect) {
    facecat.OnPaintBorderDefault(view, paint, clipRect)
}

/*
*视图的鼠标移动方法
*view 视图
*mp 坐标
*buttons 按钮 0未按下 1左键 2右键
*clicks 点击次数
*delta 滚轮值
*/
func OnMouseMove(view *facecat.FCView, mp facecat.FCPoint, buttons int, clicks int, delta int){
    facecat.OnMouseMoveDefault(view, mp, buttons, clicks, delta)
}

/*
*视图的鼠标按下方法
*view 视图
*mp 坐标
*buttons 按钮 0未按下 1左键 2右键
*clicks 点击次数
*delta 滚轮值
*/
func OnMouseDown(view *facecat.FCView, mp facecat.FCPoint, buttons int, clicks int, delta int){
	facecat.OnMouseDownDefault(view, mp, buttons, clicks, delta)
}

/*
*视图的鼠标抬起方法
*view 视图
*mp 坐标
*buttons 按钮 0未按下 1左键 2右键
*clicks 点击次数
*delta 滚轮值
*/
func OnMouseUp(view *facecat.FCView, mp facecat.FCPoint, buttons int, clicks int, delta int){
    facecat.OnMouseUpDefault(view, mp, buttons, clicks, delta)
}

/*
* 鼠标点击实现方法
* view: 图层
* firstTouch:是否第一次触摸
* firstPoint:第一次触摸的坐标
* secondTouch:是否第二次触摸
* secondPoint:第二次触摸的坐标
* clicks:点击次数
*/
func OnClick(view *facecat.FCView, firstTouch bool, firstPoint facecat.FCPoint, secondTouch bool, secondPoint facecat.FCPoint, clicks int){
    facecat.OnClickDefault(view, firstTouch, firstPoint, secondTouch, secondPoint, clicks)
	if view.ViewName == "btnOrder"{
		//代码输入框
		txtIssueCode := facecat.FindViewByName("txtIssueCode", appPaint.Views)
		//量输入框
		spinVolume := facecat.FindViewByName("spinVolume", appPaint.Views)
		//价格输入框
		spinPrice := facecat.FindViewByName("spinPrice", appPaint.Views)
		//买入单选按钮
		rbBuy := facecat.FindViewByName("rbBuy", appPaint.Views)
		//开仓按钮
		rbOpen := facecat.FindViewByName("rbOpen", appPaint.Views)
		//平今按钮
		rbCloseToday := facecat.FindViewByName("rbCloseToday", appPaint.Views)
		//平仓按钮
		rbClose := facecat.FindViewByName("rbClose", appPaint.Views)
		issueCode := facecat.GetViewAttribute(txtIssueCode, "text")
		//判断输入代码是否在码表中
		_, ok := allCodes[issueCode]
		if ok{
			//交易所ID
			exchangeID := allCodes[issueCode].exchangeID
			//量
			volume := facecat.ConvertToInt(facecat.GetViewAttribute(spinVolume, "text"))
			//价格
			price := facecat.ConvertToFloat64(facecat.GetViewAttribute(spinPrice, "text"))
			//买
			if rbBuy.GetRadioButton().Checked{
				if rbOpen.GetRadioButton().Checked{
					ctp_bidOpen(ctpUniqueID, ctp_generateReqID(ctpUniqueID), issueCode, exchangeID, price, volume, 51, "")
				}else if rbCloseToday.GetRadioButton().Checked{
					ctp_bidCloseToday(ctpUniqueID, ctp_generateReqID(ctpUniqueID), issueCode, exchangeID, price, volume, 51, "")
				}else if rbClose.GetRadioButton().Checked{
					ctp_bidClose(ctpUniqueID, ctp_generateReqID(ctpUniqueID), issueCode, exchangeID, price, volume, 51, "")
				}
			}else{
				if rbOpen.GetRadioButton().Checked{
					ctp_askOpen(ctpUniqueID, ctp_generateReqID(ctpUniqueID), issueCode, exchangeID, price, volume, 51, "")
				}else if rbCloseToday.GetRadioButton().Checked{
					ctp_askCloseToday(ctpUniqueID, ctp_generateReqID(ctpUniqueID), issueCode, exchangeID, price, volume, 51, "")
				}else if rbClose.GetRadioButton().Checked{
					ctp_askClose(ctpUniqueID, ctp_generateReqID(ctpUniqueID), issueCode, exchangeID, price, volume, 51, "")
				}
			}
		}
	}else if view.ViewName == "btnCancelOrder2"{
		//获取委托表格
		gridOrder := facecat.FindViewByName("gridOrder", appPaint.Views)
		//循环遍历所有的行
		for i := 0; i < len(gridOrder.GetGrid().Rows); i++{
			row := gridOrder.GetGrid().Rows[i]
			if row.Selected{
				orderSysID := row.Cells[0].Value
				exchangeID := row.Cells[16].Value
				//调用撤单接口
				ctp_cancelOrder(ctpUniqueID, ctp_generateReqID(ctpUniqueID), exchangeID, orderSysID, "")
				break
			}
		}
	}
	//显示持仓
	if view.ViewName == "cbInvestorPosition"{
		gridInvestorPosition := facecat.FindViewByName("gridInvestorPosition", appPaint.Views)
		gridInvestorPositionDetail := facecat.FindViewByName("gridInvestorPositionDetail", appPaint.Views) 
		gridInvestorPosition.Visible = true
		gridInvestorPositionDetail.Visible = false
		facecat.InvalidateView(gridInvestorPosition)
	}else if view.ViewName == "cbInvestorPositionDetail"{
		gridInvestorPosition := facecat.FindViewByName("gridInvestorPosition", appPaint.Views)
		gridInvestorPositionDetail := facecat.FindViewByName("gridInvestorPositionDetail", appPaint.Views) 
		gridInvestorPosition.Visible = false
		gridInvestorPositionDetail.Visible = true
		facecat.InvalidateView(gridInvestorPositionDetail)
	}
}

/*
* 鼠标滚动实现方法
* view:视图
* mp:坐标
* button:按钮
* clicks:点击次数
* delta:滚轮值
*/
func OnMouseWheel(view *facecat.FCView, mp facecat.FCPoint, buttons int, clicks int, delta int) {
    facecat.OnMouseWheelDefault(view, mp, buttons, clicks, delta)
}

/*
* 鼠标离开实现方法
* view:视图
* mp:坐标
* button:按钮
* clicks:点击次数
* delta:滚轮值
*/
func OnMouseLeave(view *facecat.FCView, mp facecat.FCPoint, buttons int, clicks int, delta int) {
    facecat.OnMouseWheelDefault(view, mp, buttons, clicks, delta)
}

/*
* 鼠标进入实现方法
* view:视图
* mp:坐标
* button:按钮
* clicks:点击次数
* delta:滚轮值
*/
func OnMouseEnter(view *facecat.FCView, mp facecat.FCPoint, buttons int, clicks int, delta int) {
    facecat.OnMouseWheelDefault(view, mp, buttons, clicks, delta)
}

/*
* 键盘按下
* view:视图
* key:按键
*/
func OnKeyDown(view *facecat.FCView, key int){
}

/*
* 键盘抬起
* view:视图
* key:按键
*/
func OnKeyUp(view *facecat.FCView, key int){
}

/*
* 更新悬浮状态
* views:视图集合
*/
func UpdateView(views []*facecat.FCView) {
    facecat.UpdateViewDefault(views)
}

/*
* 创建单元格
* grid 表格
*/
func createGridCell(grid *facecat.FCView)(*facecat.FCGridCell) {
    gridCell := facecat.CreateGridCell()
    if grid.GetPaint().DefaultUIStyle == "dark" {
        gridCell.BackColor = "none"
        gridCell.BorderColor = "none"
        gridCell.TextColor = "rgb(255,255,255)"
    } else if grid.GetPaint().DefaultUIStyle == "light" {
        gridCell.BackColor = "none"
        gridCell.BorderColor = "none"
        gridCell.TextColor = "rgb(0,0,0)"
    }
    gridCell.Font = "Default,14"
    return gridCell
}

/*
* 设置单元格样式
* cell 单元格
* value1 数据1
* value2 数据2
*/
func setCellStyle2(cell *facecat.FCGridCell, value1 string, value2 string) {
    if facecat.ConvertToFloat64(value1) > facecat.ConvertToFloat64(value2) {
        cell.TextColor = "rgb(255,0,0)"
    }else if facecat.ConvertToFloat64(value1) < facecat.ConvertToFloat64(value2) {
        cell.TextColor = "rgb(0,255,0)"
    }else {
        cell.TextColor = "rgb(255,255,255)"
    }
}

/*
* 绑定资金账户
* data 数据
*/
func bindAccount(data AccountData) {
    //找到表格
    gridTradeAccount := facecat.FindViewByName("gridTradeAccount", appPaint.Views)
	inGrid := gridTradeAccount.GetGrid()
    inGrid.HeaderHeight = 30
    gridTradeAccount.ShowHScrollBar = true
    //改变列头的宽度
	for i := 0; i < len(inGrid.Columns); i++{
        gridColumn := inGrid.Columns[i]
        gridColumn.AllowSort = false
        gridColumn.Width = 140
    }
    //创建行
    if len(inGrid.Rows) == 0 {
        row := facecat.CreateGridRow()
        inGrid.Rows = append(inGrid.Rows, row)
		for i := 0; i < len(inGrid.Columns); i++{ 
            cell1 := createGridCell(gridTradeAccount)
            cell1.SetColumn(inGrid.Columns[i])
            row.Cells = append(row.Cells, cell1)
        }
    }
    //填充数值
    inGrid.Rows[0].Cells[0].Value = facecat.ToFixed(data.balance, 0)
    inGrid.Rows[0].Cells[1].Value = facecat.ToFixed(data.closeProfit, 0)
    setCellStyle2(inGrid.Rows[0].Cells[1], facecat.ConvertFloat64ToStr(data.closeProfit), "0")
    inGrid.Rows[0].Cells[2].Value =  facecat.ToFixed(data.floatProfit, 0)
    setCellStyle2(inGrid.Rows[0].Cells[2], facecat.ConvertFloat64ToStr(data.floatProfit), "0")
    inGrid.Rows[0].Cells[3].Value = facecat.ToFixed(data.positionProfit, 0)
    setCellStyle2(inGrid.Rows[0].Cells[3], facecat.ConvertFloat64ToStr(data.positionProfit), "0")
    inGrid.Rows[0].Cells[4].Value = facecat.ToFixed(data.dynamicBalance, 0)
    inGrid.Rows[0].Cells[5].Value = facecat.ToFixed(data.currMargin, 0)
    inGrid.Rows[0].Cells[6].Value = facecat.ToFixed(data.frozenCash, 0)
    inGrid.Rows[0].Cells[7].Value = facecat.ToFixed(data.available, 0)
    inGrid.Rows[0].Cells[8].Value = facecat.ToFixed((data.risk * 100), 2) + "%"
    inGrid.Rows[0].Cells[9].Value = facecat.ToFixed(data.frozenMargin, 0)
    inGrid.Rows[0].Cells[10].Value = facecat.ToFixed(data.frozenCommission, 0)
    inGrid.Rows[0].Cells[11].Value = facecat.ToFixed(data.commission, 0)
    inGrid.Rows[0].Cells[12].Value = facecat.ToFixed(data.preBalance, 0)
    inGrid.Rows[0].Cells[13].Value = facecat.ToFixed(data.preCredit, 0)
    inGrid.Rows[0].Cells[14].Value = facecat.ToFixed(data.preMortgage, 0)
    inGrid.Rows[0].Cells[15].Value = facecat.ToFixed(data.mortgage, 0)
    inGrid.Rows[0].Cells[16].Value = facecat.ToFixed(data.withdraw, 0)
    inGrid.Rows[0].Cells[17].Value = facecat.ToFixed(data.deposit, 0)
    inGrid.Rows[0].Cells[18].Value = facecat.ToFixed(data.credit, 0)
    inGrid.Rows[0].Cells[19].Value = facecat.ToFixed(data.reserveBalance, 0)
    inGrid.Rows[0].Cells[20].Value = facecat.ToFixed(data.withdrawQuota, 0)
    //刷新界面
    facecat.InvalidateView(gridTradeAccount)
}

var allCodes = make(map[string]Security)
var allDatas = make(map[string]SecurityLatestData)

/*
* 获取组合冻结量
*/
func getFrozenAmount(data InvestorPosition)(float64) {
    posi := 0.0
    if data.posiDirection == "多" {
        posi = data.longFrozen
    }else if data.posiDirection == "空" {
        posi = data.shortFrozen
    }
    return posi
}

/*
* 绑定持仓
* data 数据
*/
func bindInvestorPosition(data []InvestorPosition) {
    //找到表格
    gridInvestorPosition := facecat.FindViewByName("gridInvestorPosition", appPaint.Views)
	inGrid := gridInvestorPosition.GetGrid()
    //循环遍历数据
	for i := 0; i < len(data); i++{
        //看看有没有已经存在的数据
        row := new(facecat.FCGridRow)
		row.IsNotEmpty = false
		for j := 0; j < len(inGrid.Rows); j++{
            if inGrid.Rows[j].Cells[0].Value + inGrid.Rows[j].Cells[1].Value == data[i].code + data[i].posiDirection{
                row = inGrid.Rows[j]
                break
            }
        }
        //如果不存在就新建一行
        if!row.IsNotEmpty{
            row = facecat.CreateGridRow()
            inGrid.Rows = append(inGrid.Rows, row)
			for j := 0; j < len(inGrid.Columns); j++{
                cell1 := createGridCell(gridInvestorPosition)
                row.Cells = append(row.Cells, cell1)
            }
        }
        //填充数据
        row.Cells[0].Value = data[i].code
		digit := allCodes[data[i].code].digit
        row.Cells[1].Value = data[i].posiDirection
        row.Cells[2].Value = facecat.ToFixed(data[i].ydPosition + data[i].todayPosition, 0)
        row.Cells[3].Value = facecat.ToFixed(data[i].ydPosition, 0)
        row.Cells[4].Value = facecat.ToFixed(data[i].todayPosition, 0)
        row.Cells[5].Value = facecat.ToFixed(data[i].position - getFrozenAmount(data[i]), 0)
        row.Cells[6].Value = facecat.ToFixed(data[i].positionCost, digit)
        row.Cells[7].Value = facecat.ToFixed(data[i].positionProfit, digit)
        setCellStyle2(row.Cells[7], facecat.ConvertFloat64ToStr(data[i].positionProfit), "0")
        row.Cells[8].Value = facecat.ToFixed(data[i].margin, 0)
        row.Cells[9].Value = data[i].hedgeFlag;
		_, ok := allCodes[data[i].code]
        if ok {
            row.Cells[10].Value = allCodes[data[i].code].exchangeID
        } else {
            row.Cells[10].Value = ""
        }
        row.Cells[11].Value = "0"
        row.Cells[12].Value = "0"
        row.Cells[13].Value = "0"
        row.Cells[14].Value = "0"
        row.Cells[15].Value = "0"
        row.Cells[16].Value = "0"
        row.Cells[17].Value = "0"
        row.Cells[18].Value = "0"
        row.Cells[19].Value = "0"
        row.Cells[20].Value = "0"
        row.Cells[21].Value = "0"
        row.Cells[22].Value = "0"
        row.Cells[23].Value = "0"
        row.Cells[24].Value = "0"
        row.Cells[25].Value = facecat.ToFixed(data[i].floatProfit, digit)
        setCellStyle2(row.Cells[25], facecat.ConvertFloat64ToStr(data[i].floatProfit), "0")
        row.Cells[26].Value = "0"
        row.Cells[27].Value = "0"
        row.Cells[28].Value = "0"
        row.Cells[29].Value = "0"
        row.Cells[30].Value = "0"
    }
    //清除掉持仓量为0的行
    for{
        hasValue := false
        rowsSize := len(inGrid.Rows)
		for i := 0; i < rowsSize; i++{
            if inGrid.Rows[i].Cells[2].Value == "0"{
				inGrid.Rows = append(inGrid.Rows[:i], inGrid.Rows[i + 1:]...)
                hasValue = true
                break
            }
        }
        if !hasValue{
            break
        }
    }
    //刷新界面
    facecat.InvalidateView(gridInvestorPosition)
}

/*
* 绑定持仓明细
* data 数据
*/
func bindInvestorPositionDetail(data []InvestorPositionDetail) {
    //找到表格
    gridInvestorPositionDetail := facecat.FindViewByName("gridInvestorPositionDetail", appPaint.Views)
	inGrid := gridInvestorPositionDetail.GetGrid()
    //循环遍历数据
	for i := 0; i < len(data); i++{
        //看看有没有已经存在的数据
        row := new(facecat.FCGridRow)
		row.IsNotEmpty = false
		for j := 0; j < len(inGrid.Rows); j++{
            if inGrid.Rows[j].Cells[0].Value == data[i].tradeID{
                row = inGrid.Rows[j]
                break
            }
        }
        //如果不存在就新建一行
        if(!row.IsNotEmpty){
            row = facecat.CreateGridRow()
            inGrid.Rows = append(inGrid.Rows, row)
			for j := 0; j < len(inGrid.Columns); j++{
                cell1 := createGridCell(gridInvestorPositionDetail)
                row.Cells = append(row.Cells, cell1)
            }
        }
        //填充数据
        row.Cells[0].Value = data[i].tradeID
        row.Cells[1].Value = data[i].code
		digit := allCodes[data[i].code].digit
        row.Cells[2].Value = data[i].direction
        row.Cells[3].Value = facecat.ToFixed(data[i].volume, 0)
        row.Cells[4].Value = facecat.ToFixed(data[i].openPrice, digit)
        row.Cells[5].Value = facecat.ToFixed(data[i].margin, 0)
        row.Cells[6].Value = data[i].tradeType
        row.Cells[7].Value = data[i].hedgeFlag
        row.Cells[8].Value = data[i].openDate
        row.Cells[9].Value = facecat.ToFixed(data[i].positionProfit, digit)
        row.Cells[10].Value = facecat.ToFixed(data[i].closeProfitByTrade, digit)
        row.Cells[11].Value =  data[i].exchangeID
        row.Cells[12].Value = "普通持仓"
        row.Cells[13].Value = facecat.ToFixed(data[i].preSettlementPrice, digit)
        row.Cells[14].Value = facecat.ToFixed(data[i].closeVolume, 0)
        row.Cells[15].Value = facecat.ToFixed(data[i].floatProfit, digit)
        row.Cells[16].Value = facecat.ToFixed(data[i].openPrice, digit)
        row.Cells[17].Value = data[i].combInstrumentID
    }
    //清除掉持仓量为0的行
    for{
        hasValue := false
        rowsSize := len(inGrid.Rows)
		for i := 0; i < rowsSize; i++{
            if inGrid.Rows[i].Cells[3].Value == "0"{
				inGrid.Rows = append(inGrid.Rows[:i], inGrid.Rows[i + 1:]...)
                hasValue = true
                break
            }
        }
        if !hasValue{
            break
        }
    }
    //刷新界面
    facecat.InvalidateView(gridInvestorPositionDetail)
}

/*
* 增加委托回报回调
* data 数据
*/
func addOrderInfo(data OrderInfo) {
    //过滤数据
    if data.orderStatus == "未知" {
        return
    }
    if len(data.orderSysID) == 0{
        return;
    }
    //找到表格
    gridOrder := facecat.FindViewByName("gridOrder", appPaint.Views)
	inGrid := gridOrder.GetGrid()
    //看看有没有已经存在的数据
    row := new(facecat.FCGridRow)
	row.IsNotEmpty = false
	for j := 0; j < len(inGrid.Rows); j++{
        if inGrid.Rows[j].Cells[0].Value == data.orderSysID{
            row = inGrid.Rows[j]
            break;
        }
    }
    //如果不存在就新建一行
    if(!row.IsNotEmpty){
        row = facecat.CreateGridRow()
		var newRows []*facecat.FCGridRow
		newRows = append(newRows, row)
		for i := 0; i < len(inGrid.Rows); i++{
			newRows = append(newRows, inGrid.Rows[i])
		}
		inGrid.Rows = newRows
		for j := 0; j < len(inGrid.Columns); j++{
            cell1 := createGridCell(gridOrder)
            row.Cells = append(row.Cells, cell1)
        }
    }
    //填充数据
    row.Cells[0].Value = data.orderSysID
    row.Cells[1].Value = data.code
	digit := allCodes[data.code].digit
    row.Cells[2].Value = data.direction
    row.Cells[3].Value = data.combOffsetFlag
    row.Cells[4].Value = data.orderStatus
    row.Cells[5].Value = facecat.ToFixed(data.limitPrice, digit)
    row.Cells[6].Value = facecat.ToFixed(data.volumeTotalOriginal, 0)
    row.Cells[7].Value = facecat.ToFixed(data.volumeTotal, 0)
    row.Cells[8].Value = facecat.ToFixed(data.volumeTotal, 0)
    row.Cells[9].Value = facecat.ToFixed(data.volumeTraded, 0)
    row.Cells[10].Value = data.insertTime
    row.Cells[11].Value = data.updateTime
    row.Cells[12].Value = facecat.ToFixed(data.limitPrice, digit)
    row.Cells[13].Value = "0"
    row.Cells[14].Value = "0"
    row.Cells[15].Value = data.combHedgeFlag
    row.Cells[16].Value = data.exchangeID
    row.Cells[17].Value = data.orderPriceType
    row.Cells[18].Value = data.timeCondition
    row.Cells[19].Value = data.orderType
    row.Cells[20].Value = facecat.ToFixed(data.userForceClose, 0)
    row.Cells[21].Value = data.forceCloseReason
    row.Cells[22].Value = ""
    row.Cells[23].Value = ""
    //刷新界面
    facecat.InvalidateView(gridOrder)
}

/*
* 绑定定委托回报历史数据
* data 数据
*/
func bindOrderInfos(data []OrderInfo) {
    //找到表格
    gridOrder := facecat.FindViewByName("gridOrder", appPaint.Views)
	inGrid := gridOrder.GetGrid()
    //清除掉所有的行
	var newRows []*facecat.FCGridRow
    inGrid.Rows = newRows
    //循环遍历所有的数据
	for i := 0; i < len(data); i++{
        //过滤数据
        if data[i].orderStatus == "未知" {
            continue
        }
        if len(data[i].orderSysID) == 0 {
            return
        }
        //看看有没有已经存在的数据
        row := new(facecat.FCGridRow)
		row.IsNotEmpty = false
		for j := 0; j < len(inGrid.Rows); j++{
            if inGrid.Rows[j].Cells[0].Value == data[i].orderSysID {
                row = inGrid.Rows[j]
                break
            }
        }
        //如果不存在就新建一行
        if !row.IsNotEmpty{
			row = facecat.CreateGridRow()
            inGrid.Rows = append(inGrid.Rows, row)
			for j := 0; j < len(inGrid.Columns); j++{
                cell1 := createGridCell(gridOrder)
				row.Cells = append(row.Cells, cell1)
            }
        }
        //填充数据
        row.Cells[0].Value = data[i].orderSysID
        row.Cells[1].Value = data[i].code
		digit := allCodes[data[i].code].digit
        row.Cells[2].Value = data[i].direction
        row.Cells[3].Value = data[i].combOffsetFlag
        row.Cells[4].Value = data[i].orderStatus
        row.Cells[5].Value = facecat.ToFixed(data[i].limitPrice, digit)
        row.Cells[6].Value = facecat.ToFixed(data[i].volumeTotalOriginal, 0)
        row.Cells[7].Value = facecat.ToFixed(data[i].volumeTotal, 0)
        row.Cells[8].Value = facecat.ToFixed(data[i].volumeTotal, 0)
        row.Cells[9].Value = facecat.ToFixed(data[i].volumeTraded, 0)
        row.Cells[10].Value = data[i].insertTime
        row.Cells[11].Value = data[i].updateTime
        row.Cells[12].Value = facecat.ToFixed(data[i].limitPrice, digit)
        row.Cells[13].Value = "0"
        row.Cells[14].Value = "0"
        row.Cells[15].Value = data[i].combHedgeFlag
        row.Cells[16].Value = data[i].exchangeID
        row.Cells[17].Value = data[i].orderPriceType
        row.Cells[18].Value = data[i].timeCondition
        row.Cells[19].Value = data[i].orderType
        row.Cells[20].Value = facecat.ToFixed(data[i].userForceClose, 0)
        row.Cells[21].Value = data[i].forceCloseReason
        row.Cells[22].Value = ""
        row.Cells[23].Value = ""
    }
    //刷新界面
    facecat.InvalidateView(gridOrder)
}

/*
* 添加成交回报
* data 数据
*/
func addTradeRecord(data TradeRecord) {
    //过滤数据
    if len(data.tradeID) == 0 {
        return
    }
    //找到表格
    gridTradeRecord := facecat.FindViewByName("gridTradeRecord", appPaint.Views)
	inGrid := gridTradeRecord.GetGrid()
    //填充数据
    row := facecat.CreateGridRow() 
	var newRows []*facecat.FCGridRow
	newRows = append(newRows, row)
	for i := 0; i < len(inGrid.Rows); i++{
		newRows = append(newRows, inGrid.Rows[i])
	}
	inGrid.Rows = newRows
    cell1 := createGridCell(gridTradeRecord)
    cell1.Value = data.tradeID
    row.Cells = append(row.Cells, cell1)
    cell2 := createGridCell(gridTradeRecord)
    cell2.Value = data.code
	digit := allCodes[data.code].digit
    row.Cells = append(row.Cells, cell2)
    cell3 := createGridCell(gridTradeRecord)
    cell3.Value = data.direction
    row.Cells = append(row.Cells, cell3)
    cell4 := createGridCell(gridTradeRecord)
    cell4.Value = data.offsetFlag
    row.Cells = append(row.Cells, cell4)
    cell5 := createGridCell(gridTradeRecord)
    cell5.Value = facecat.ToFixed(data.price, digit)
    row.Cells = append(row.Cells, cell5)
    cell6 := createGridCell(gridTradeRecord);
    cell6.Value = facecat.ToFixed(data.volume, 0)
    row.Cells = append(row.Cells, cell6)
    cell7 := createGridCell(gridTradeRecord)
    cell7.Value = data.tradeTime
    row.Cells = append(row.Cells, cell7)
    cell8 := createGridCell(gridTradeRecord)
    cell8.Value = data.orderSysID
    row.Cells = append(row.Cells, cell8)
    cell9 := createGridCell(gridTradeRecord)
    cell9.Value = "普通成交"
    row.Cells = append(row.Cells, cell9)
    cell10 := createGridCell(gridTradeRecord)
    cell10.Value = data.hedgeFlag
    row.Cells = append(row.Cells, cell10)
    cell11 := createGridCell(gridTradeRecord)
    cell11.Value = data.exchangeID
    row.Cells = append(row.Cells, cell11)
    cell12 := createGridCell(gridTradeRecord)
    cell12.Value = facecat.ToFixed(data.commission, digit)
    row.Cells = append(row.Cells, cell12)
    //刷新界面
    facecat.InvalidateView(gridTradeRecord)
}

/*
* 绑定成交回报历史数据
* data 数据
*/
func bindTradeRecords(data []TradeRecord) {
    //找到表格
    gridTradeRecord := facecat.FindViewByName("gridTradeRecord", appPaint.Views)
	inGrid := gridTradeRecord.GetGrid()
    //清除所有的行
	var newRows []*facecat.FCGridRow
    inGrid.Rows = newRows
    //循环遍历数据
	for i := 0; i < len(data); i++{
        if len(data[i].tradeID) == 0 {
            return
        }
        //填充数据
        row := facecat.CreateGridRow() 
        inGrid.Rows = append(inGrid.Rows, row)
        cell1 := createGridCell(gridTradeRecord)
        cell1.Value = data[i].tradeID
        row.Cells = append(row.Cells, cell1)
        cell2 := createGridCell(gridTradeRecord)
        cell2.Value = data[i].code
		digit := allCodes[data[i].code].digit
        row.Cells = append(row.Cells, cell2)
        cell3 := createGridCell(gridTradeRecord)
        cell3.Value = data[i].direction
        row.Cells = append(row.Cells, cell3)
        cell4 := createGridCell(gridTradeRecord)
        cell4.Value = data[i].offsetFlag
        row.Cells = append(row.Cells, cell4)
        cell5 := createGridCell(gridTradeRecord)
        cell5.Value = facecat.ToFixed(data[i].price, digit)
        row.Cells = append(row.Cells, cell5)
        cell6 := createGridCell(gridTradeRecord)
        cell6.Value = facecat.ToFixed(data[i].volume, 0)
        row.Cells = append(row.Cells, cell6)
        cell7 := createGridCell(gridTradeRecord)
        cell7.Value = data[i].tradeTime
        row.Cells = append(row.Cells, cell7)
        cell8 := createGridCell(gridTradeRecord)
        cell8.Value = data[i].orderSysID
        row.Cells = append(row.Cells, cell8)
        cell9 := createGridCell(gridTradeRecord)
        cell9.Value = "普通成交"
        row.Cells = append(row.Cells, cell9)
        cell10 := createGridCell(gridTradeRecord)
        cell10.Value = data[i].hedgeFlag
        row.Cells = append(row.Cells, cell10)
        cell11 := createGridCell(gridTradeRecord)
        cell11.Value = data[i].exchangeID
        row.Cells = append(row.Cells, cell11)
        cell12 := createGridCell(gridTradeRecord)
        cell12.Value = facecat.ToFixed(data[i].commission, digit)
        row.Cells = append(row.Cells, cell12)
    }
    //刷新界面
    facecat.InvalidateView(gridTradeRecord)
}

/*
* 绑定码表
* data 数据
*/
func bindSecurity(data []Security) {
    //找到表格
    contractGrid := facecat.FindViewByName("gridContracts", appPaint.Views)
	inGrid := contractGrid.GetGrid()
    //清除行
	var newRows []*facecat.FCGridRow
    inGrid.Rows = newRows
    //循环遍历所有的行
	for i := 0; i < len(data); i++{
        //保存数据
        allCodes[data[i].instrumentID] = data[i]
        //填充数据
		row := facecat.CreateGridRow() 
        inGrid.Rows = append(inGrid.Rows, row)
        cell1 := createGridCell(contractGrid)
        cell1.Value = data[i].productID
        row.Cells = append(row.Cells, cell1)
        cell2 := createGridCell(contractGrid)
        cell2.Value = data[i].instrumentID
        row.Cells = append(row.Cells, cell2)
        cell3 := createGridCell(contractGrid)
        cell3.Value = data[i].instrumentName
        row.Cells = append(row.Cells, cell3) 
        cell4 := createGridCell(contractGrid)
        cell4.Value = data[i].exchangeID
        row.Cells = append(row.Cells, cell4)
        cell5 := createGridCell(contractGrid)
        cell5.Value = facecat.ToFixed(data[i].volumeMultiple, 0)
        row.Cells = append(row.Cells, cell5)
        cell6 := createGridCell(contractGrid)
        cell6.Value = facecat.ToFixed(data[i].priceTick, 2)
        row.Cells = append(row.Cells, cell6)
        cell7 := createGridCell(contractGrid)
        cell7.Value = "期货"
        row.Cells = append(row.Cells, cell7)
        cell8 := createGridCell(contractGrid)
        cell8.Value = data[i].expireDate
        row.Cells = append(row.Cells, cell8)
        cell9 := createGridCell(contractGrid)
        cell9.Value = facecat.ToFixed(data[i].longMarginRatio, 2)
        row.Cells = append(row.Cells, cell9)
        cell10 := createGridCell(contractGrid)
        cell10.Value = facecat.ToFixed(data[i].shortMarginRatio, 2)
        row.Cells = append(row.Cells, cell10)
        cell11 := createGridCell(contractGrid)
        cell11.Value = "0"
        row.Cells = append(row.Cells, cell11)
        cell12 := createGridCell(contractGrid)
        cell12.Value = "0"
        row.Cells = append(row.Cells, cell12)
        cell13 := createGridCell(contractGrid)
        cell13.Value = "0"
        row.Cells = append(row.Cells, cell13)
        cell14 := createGridCell(contractGrid)
        cell14.Value = "0"
        row.Cells = append(row.Cells, cell14)
        cell15 := createGridCell(contractGrid)
        cell15.Value = "0"
        row.Cells = append(row.Cells, cell15)
        cell16 := createGridCell(contractGrid)
        cell16.Value = "0"
        row.Cells = append(row.Cells, cell16)
        cell17 := createGridCell(contractGrid)
        cell17.Value = facecat.ToFixed(data[i].maxMarketOrderVolume, 0)
        row.Cells = append(row.Cells, cell17)
        cell18 := createGridCell(contractGrid)
        cell18.Value = facecat.ToFixed(data[i].maxLimitOrderVolume, 0)
        row.Cells = append(row.Cells, cell18)
    }
    //刷新界面
    facecat.InvalidateView(contractGrid)
};

//当前的代码
var currentCode = "cu2312"

/*
* 绑定最新数据
* data 数据
*/
func bindSecurityLatestData(data []SecurityLatestData) {
    gridLatestData := facecat.FindViewByName("gridLatestData", appPaint.Views)
	inGrid := gridLatestData.GetGrid()
    //找到K线
    chart := facecat.FindViewByName("chart", appPaint.Views)
    //循环遍历数据
	for d := 0; d < len(data); d++{
        //看看有没有已经存在的数据
        row := new(facecat.FCGridRow)
		row.IsNotEmpty = false
		for i := 0; i < len(inGrid.Rows); i++{
            if inGrid.Rows[i].Cells[0].Value == data[d].code {
                row = inGrid.Rows[i]
                break
            }
        }
        //如果不存在就新建一行
        if !row.IsNotEmpty{
            row = facecat.CreateGridRow()
            inGrid.Rows = append(inGrid.Rows, row)
			for j := 0; j < len(inGrid.Columns); j++{
                cell1 := createGridCell(gridLatestData)
                row.Cells = append(row.Cells, cell1)
            }
        }
        //填充数据
        row.Cells[0].Value = data[d].code
        newVol := 0.0
		_, ok := allDatas[data[d].code]
        if ok {
            newVol = data[d].volume - allDatas[data[d].code].volume;
        }
        allDatas[data[d].code] =  data[d]
        digit := 0
		_, ok2 := allCodes[data[d].code]
        if ok2 {
            row.Cells[1].Value = allCodes[data[d].code].instrumentName
        }
        digit = allCodes[data[d].code].digit
        setCellStyle2(row.Cells[2], row.Cells[2].Value, facecat.ConvertFloat64ToStr(data[d].close))
        row.Cells[2].Value = facecat.ToFixed(data[d].close, digit)
        diff := data[d].close - data[d].preSettlementPrice
        setCellStyle2(row.Cells[3], facecat.ToFixed(diff, 2), "0")
        row.Cells[3].Value = facecat.ToFixed(diff, digit)
        setCellStyle2(row.Cells[4], row.Cells[4].Value, facecat.ConvertFloat64ToStr(data[d].bidPrice1))
        row.Cells[4].Value = facecat.ToFixed(data[d].bidPrice1, digit)
        row.Cells[5].Value = facecat.ToFixed(float64(data[d].bidVolume1), 0)
        setCellStyle2(row.Cells[6], row.Cells[6].Value, facecat.ConvertFloat64ToStr(data[d].askPrice1))
        row.Cells[6].Value = facecat.ToFixed(data[d].askPrice1, digit)
        row.Cells[7].Value = facecat.ToFixed(float64(data[d].askVolume1), 0)
        row.Cells[8].Value = facecat.ToFixed(data[d].volume, 0)
        row.Cells[9].Value = facecat.ToFixed(data[d].openInterest, digit)
        row.Cells[10].Value = facecat.ToFixed(data[d].upperLimit, digit)
        row.Cells[11].Value = facecat.ToFixed(data[d].lowerLimit, digit)
        setCellStyle2(row.Cells[12], row.Cells[12].Value, facecat.ConvertFloat64ToStr(data[d].open))
        row.Cells[12].Value = facecat.ToFixed(data[d].open, digit)
        row.Cells[13].Value = facecat.ToFixed(data[d].preSettlementPrice, digit)
        setCellStyle2(row.Cells[14], row.Cells[14].Value, facecat.ConvertFloat64ToStr(data[d].high))
        row.Cells[14].Value = facecat.ToFixed(data[d].high, digit)
        setCellStyle2(row.Cells[15], row.Cells[15].Value, facecat.ConvertFloat64ToStr(data[d].low))
        row.Cells[15].Value = facecat.ToFixed(data[d].low, digit)
        row.Cells[16].Value = facecat.ToFixed(float64(data[d].bidVolume1), 0)
        rangeValue := 0.0
        if data[d].preSettlementPrice != 0 {
            rangeValue = 100 * (data[d].close - data[d].preSettlementPrice) / data[d].preSettlementPrice
        }
        row.Cells[17].Value = facecat.ToFixed(rangeValue, digit) + "%"
        setCellStyle2(row.Cells[17], facecat.ConvertFloat64ToStr(rangeValue), "0");
        row.Cells[18].Value = facecat.ToFixed(data[d].preClose, digit)
        row.Cells[19].Value = facecat.ToFixed(data[d].turnover, digit)
        row.Cells[20].Value = data[d].exchangeID
        row.Cells[21].Value = data[d].updateTime
        row.Cells[22].Value = facecat.ToFixed(data[d].preOpenInterest, digit)
        row.Cells[23].Value = facecat.ToFixed(data[d].close, digit)
        row.Cells[24].Value = facecat.ToFixed(data[d].settlementPrice, digit)
        row.Cells[25].Value = facecat.ToFixed(data[d].averagePrice, digit)
        row.Cells[26].Value = "0"
        row.Cells[27].Value = "0"
        row.Cells[28].Value = "0"
        row.Cells[29].Value = "0"
        row.Cells[30].Value = "0"
        row.Cells[31].Value = "0"
        ////填充到K线
        if newVol > 0 {
            if data[d].code == currentCode {
                sData := new(facecat.SecurityData)
                sData.Date = float64(len(chart.GetChart().Data) + 1)
                sData.Close = data[d].close
                sData.Open = data[d].close
                sData.High = data[d].close
                sData.Low = data[d].close
                sData.Volume = newVol
                chart.GetChart().Data = append(chart.GetChart().Data, sData)
            }
        }
    }
    //刷新界面
    facecat.ResetChartVisibleRecord(chart)
    facecat.CheckChartLastVisibleIndex(chart)
    facecat.CalcChartIndicator(chart)
    facecat.InvalidateView(chart)
    facecat.InvalidateView(gridLatestData)
}

/*
*点击单元格
*/
func OnClickGridCell(grid *facecat.FCView, row *facecat.FCGridRow, gridColumn *facecat.FCGridColumn, cell *facecat.FCGridCell, firstTouch bool, firstPoint facecat.FCPoint, secondTouch bool, secondPoint facecat.FCPoint, clicks int){
	gridName := grid.ViewName
	if gridName == "gridLatestData"{
		//从选中的最新行情自动填写信息到下单界面中
		chart := facecat.FindViewByName("chart", appPaint.Views)
		inChart := chart.GetChart()
		var newData[] *facecat.SecurityData
		inChart.Data = newData
		facecat.CalculateChartMaxMin(chart)
		code := row.Cells[0].Value
		currentCode = code
		price := facecat.ConvertToFloat64(row.Cells[2].Value)
		digit := 0
		_, ok2 := allCodes[code]
        if ok2 {
            digit = allCodes[code].digit
        }
		txtIssueCode := facecat.FindViewByName("txtIssueCode", appPaint.Views)
		spinPrice := facecat.FindViewByName("spinPrice", appPaint.Views)
		spinVolume := facecat.FindViewByName("spinVolume", appPaint.Views)
		facecat.SetViewAttribute(txtIssueCode, "text", code)
		facecat.SetViewAttribute(spinPrice, "text", facecat.ToFixed(price, digit))
		facecat.SetViewAttribute(spinVolume, "text", "1")
		facecat.Invalidate(appPaint)
	}else if gridName == "gridInvestorPosition"{
		//从选中的持仓自动填写信息到下单界面中
		code := row.Cells[0].Value
		price := 0.0
		_, ok := allDatas[code]
		digit := 0
		if ok{
			price = allDatas[code].close
			digit = allCodes[code].digit
		}
		txtIssueCode := facecat.FindViewByName("txtIssueCode", appPaint.Views)
		spinPrice := facecat.FindViewByName("spinPrice", appPaint.Views)
		spinVolume := facecat.FindViewByName("spinVolume", appPaint.Views)
		facecat.SetViewAttribute(txtIssueCode, "text", code)
		facecat.SetViewAttribute(spinPrice, "text", facecat.ToFixed(price, digit))
		facecat.SetViewAttribute(spinVolume, "text", "1")
		facecat.Invalidate(appPaint)
	}else if(gridName == "gridInvestorPositionDetail"){
		//从选中的持仓明细自动填写信息到下单界面中
		code := row.Cells[0].Value
		price := 0.0
		_, ok := allDatas[code]
		digit := 0
		if ok{
			price = allDatas[code].close
			digit = allCodes[code].digit
		}
		txtIssueCode := facecat.FindViewByName("txtIssueCode", appPaint.Views)
		spinPrice := facecat.FindViewByName("spinPrice", appPaint.Views)
		spinVolume := facecat.FindViewByName("spinVolume", appPaint.Views)
		facecat.SetViewAttribute(txtIssueCode, "text", code)
		facecat.SetViewAttribute(spinPrice, "text", facecat.ToFixed(price, digit))
		facecat.SetViewAttribute(spinVolume, "text", "1")
		facecat.Invalidate(appPaint)
	}
}

/*
*检查CTP的数据
*/
func checkCTPData(){
	for{
		if ctp_hasNewDatas(ctpUniqueID){
			//获取最新数据
			recvData := ctp_getDepthMarketData(ctpUniqueID)
			if len(recvData) > 0{
				depthMarketData := convertToCTPDepthMarketData(recvData)
				bindSecurityLatestData(depthMarketData)
				continue
			}
			//获取资金账号
			recvData = ctp_getAccountData(ctpUniqueID)
			if len(recvData) > 0{
				accountData := convertToCTPAccountData(recvData)
				bindAccount(accountData)
				continue
			}
			//获取委托回报
			recvData = ctp_getOrderInfo(ctpUniqueID)
			if len(recvData) > 0{
				orderInfo := convertToCTPOrder(recvData)
				addOrderInfo(orderInfo)
				continue
			}
			//获取成交回报
			recvData = ctp_getTradeRecord(ctpUniqueID)
			if len(recvData) > 0{
				tradeRecord := convertToCTPTrade(recvData)
				addTradeRecord(tradeRecord)
				continue
			}
			//获取持仓
			recvData = ctp_getPositionData(ctpUniqueID)
			if len(recvData) > 0{
				positionData := convertToCTPInvestorPosition(recvData)
				bindInvestorPosition(positionData)
				continue
			}
			//获取持仓明细
			recvData = ctp_getPositionDetailData(ctpUniqueID)
			if len(recvData) > 0{
				positionDetailData := convertToCTPInvestorPositionDetail(recvData)
				bindInvestorPositionDetail(positionDetailData)
				continue
			}
		}else{
			break
		}
	}
}

/*
*启动CTP
*/
func runCTP(){
	ctpUniqueID = ctp_create()
	ctp_setEncoding(1)
	reqID := ctp_generateReqID(ctpUniqueID)
	//第一组 行情:180.168.146.187:10211 交易:180.168.146.187:10201
	//第二组 行情:180.168.146.187:10212 交易:180.168.146.187:10202
	//第三组 行情:218.202.237.33:10213 交易:218.202.237.33:10203
	//第四组 行情:180.168.146.187:10131 交易:180.168.146.187:10130
	ctp_start(ctpUniqueID, reqID, "simnow_client_test", "0000000000000000", "218.202.237.33:10213", "218.202.237.33:10203", "9999", "021739", "123456")
	for{
		if ctp_isDataOk(ctpUniqueID){
			break
		}else{
			time.Sleep(time.Duration(1) * time.Second)
		}
	}
	time.Sleep(time.Duration(1) * time.Second)
	//获取码表
	recvData := ctp_getInstrumentsData(ctpUniqueID)
	instrumentsData := convertToCTPInstrumentDatas(recvData)
	bindSecurity(instrumentsData)
	//获取委托回报历史
	recvData = ctp_getOrderInfos(ctpUniqueID)
	orderInfos := convertToCTPOrderList(recvData)
	bindOrderInfos(orderInfos)
	//获取成交回报历史
	recvData = ctp_getTradeRecords(ctpUniqueID)
	tradeRecords := convertToCTPTradeRecords(recvData)
    bindTradeRecords(tradeRecords)
	ctp_setMessageID(ctpUniqueID, int(appPaint.HWnd), 2000)
	ctp_subMarketDatas(ctpUniqueID, reqID, "cu2403,cu2404,cu2405,rb2403,rb2404,rb2405,ru2403,ru2404,ru2405")	
	//facecat.SetTimerW32(appPaint.HWnd, 1000, 100, 0)	
}

var appPaint = new(facecat.FCPaint)

func WndProc(hwnd facecat.HWND, msg uint32, wParam, lParam uintptr) (result uintptr) {
	if msg == 2000{
		checkCTPData();
		return 1;
	}else{
		if msg == facecat.WM_TIMER{
			if int(wParam) == 1000{
				checkCTPData()
			}
		}
		handle := facecat.WndProcDefault(appPaint, hwnd, msg, wParam, lParam)
		return handle
	}
}

func main() {
	appPaint = facecat.CreatePaint()
	appPaint.AllowPartialPaint = false
	appPaint.SystemFont = "SimSun"
	appPaint.DefaultUIStyle = "dark"
    appPaint.OnPaint = OnPaint
    appPaint.OnPaintBorder = OnPaintBorder
    appPaint.OnMouseDown = OnMouseDown
    appPaint.OnMouseMove = OnMouseMove
    appPaint.OnMouseUp = OnMouseUp
    appPaint.OnMouseWheel = OnMouseWheel
    appPaint.OnClick = OnClick
    appPaint.OnUpdateView = UpdateView
    appPaint.OnMouseLeave = OnMouseLeave
    appPaint.OnMouseEnter = OnMouseEnter
    appPaint.OnKeyDown = OnKeyDown
    appPaint.OnKeyUp = OnKeyUp
	appPaint.OnClickGridCell = OnClickGridCell
	facecat.SetMaxWindow()
    facecat.CreateMainWindow(appPaint, "FaceCat-Go", WndProc)
     xmlStr, _ := ioutil.ReadFile("mainframe.xml")
    facecat.RenderFaceCat(appPaint, string(xmlStr))
	//获取K线
    chart := facecat.FindViewByName("chart", appPaint.Views)
	inChart := chart.GetChart()
    inChart.CandleDivPercent = 0.7
    inChart.VolDivPercent = 0.3
    inChart.IndDivPercent = 0
    inChart.Cycle = "trend"
	chart.BackColor = "rgb(0,0,0)";
	chart.BorderColor = "rgb(100,100,100)";
	chart.TextColor = "rgb(255,255,255)";
	inChart.ScaleColor = "rgb(100,100,100)";
	inChart.CrossTipColor = "rgb(50,50,50)";
	inChart.CrossLineColor = "rgb(100,100,100)";
	inChart.GridColor = "rgba(100,100,100,125)";
	var indicatorColors[] string
	inChart.IndicatorColors = indicatorColors
	inChart.IndicatorColors = append(inChart.IndicatorColors, "rgb(255,255,255)")
	inChart.IndicatorColors = append(inChart.IndicatorColors, "rgb(255,255,0)")
	inChart.IndicatorColors = append(inChart.IndicatorColors, "rgb(255,0,255)")
	inChart.IndicatorColors = append(inChart.IndicatorColors, "rgb(255,0,0)")
	inChart.IndicatorColors = append(inChart.IndicatorColors, "rgb(0,255,255)")
	inChart.IndicatorColors = append(inChart.IndicatorColors, "rgb(0,255,0)")
	inChart.IndicatorColors = append(inChart.IndicatorColors, "rgb(255,255,0)")
	inChart.IndicatorColors = append(inChart.IndicatorColors, "rgb(255,255,255)")
	go runCTP()
    facecat.ShowWindow(appPaint)
}
